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 if ( !obj->_non_existent() )
241 aShapeObj = GEOM::GEOM_Object::_narrow ( obj );
244 return aShapeObj._retn();
247 //=======================================================================
248 //function : GeomObjectToShape
250 //=======================================================================
252 TopoDS_Shape SMESH_Gen_i::GeomObjectToShape(GEOM::GEOM_Object_ptr theGeomObject)
255 if ( !theGeomObject->_is_nil() && !theGeomObject->_non_existent() ) {
256 GEOM_Client* aClient = GetShapeReader();
257 GEOM::GEOM_Gen_ptr aGeomEngine = GetGeomEngine();
258 if ( aClient && !aGeomEngine->_is_nil () )
259 S = aClient->GetShape( aGeomEngine, theGeomObject );
264 //=======================================================================
267 //=======================================================================
269 static SALOMEDS::SObject_ptr publish(CORBA::Object_ptr theIOR,
270 SALOMEDS::SObject_ptr theFatherObject,
271 const int theTag = 0,
272 const char* thePixMap = 0,
273 const bool theSelectable = true)
275 SALOMEDS::Study_var theStudy = SMESH_Gen_i::getStudyServant();
276 SALOMEDS::SObject_wrap SO = SMESH_Gen_i::ObjectToSObject( theIOR );
277 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
278 SALOMEDS::UseCaseBuilder_wrap useCaseBuilder = theStudy->GetUseCaseBuilder();
279 bool isNewSO = false, isInUseCaseTree = false;
283 SO = aStudyBuilder->NewObject( theFatherObject );
286 else if ( !theFatherObject->FindSubObject( theTag, SO.inout() ))
288 SO = aStudyBuilder->NewObjectToTag( theFatherObject, theTag );
293 isInUseCaseTree = useCaseBuilder->IsUseCaseNode( SO );
298 isInUseCaseTree = useCaseBuilder->IsUseCaseNode( SO );
301 SALOMEDS::GenericAttribute_wrap anAttr;
302 if ( !CORBA::is_nil( theIOR ))
304 anAttr = aStudyBuilder->FindOrCreateAttribute( SO, "AttributeIOR" );
305 CORBA::String_var objStr = SMESH_Gen_i::GetORB()->object_to_string( theIOR );
306 SALOMEDS::AttributeIOR_wrap iorAttr = anAttr;
307 CORBA::String_var objStrCur = iorAttr->Value();
308 bool sameIOR = ( objStrCur.in() && strcmp( objStr.in(), objStrCur.in() ) == 0 );
311 iorAttr->SetValue( objStr.in() );
312 // UnRegister() !!! --> random problems when meshing in parallel (yacs foreach) in
313 // distributed python scripts, because simultaneously created meshes are
314 // published into the same SO; as a result the mesh published first dies
315 SALOME::GenericObj_var genObj = SALOME::GenericObj::_narrow( theIOR );
316 if ( !genObj->_is_nil() )
317 genObj->UnRegister();
322 anAttr = aStudyBuilder->FindOrCreateAttribute( SO, "AttributePixMap" );
323 SALOMEDS::AttributePixMap_wrap pm = anAttr;
324 pm->SetPixMap( thePixMap );
327 if ( !theSelectable ) {
328 anAttr = aStudyBuilder->FindOrCreateAttribute( SO, "AttributeSelectable" );
329 SALOMEDS::AttributeSelectable_wrap selAttr = anAttr;
330 selAttr->SetSelectable( false );
334 aStudyBuilder->RemoveReference( SO );// remove garbage reference (23336)
336 // add object to the use case tree
337 // (to support tree representation customization and drag-n-drop)
338 if ( isNewSO || !isInUseCaseTree )
340 // define the next tag after given one in the data tree to insert SObject
341 SALOMEDS::SObject_wrap curObj, objAfter;
342 if ( theFatherObject->GetLastChildTag() > theTag && theTag > 0 )
344 SALOMEDS::UseCaseIterator_wrap
345 anUseCaseIter = useCaseBuilder->GetUseCaseIterator(theFatherObject);
346 for ( ; anUseCaseIter->More(); anUseCaseIter->Next() ) {
347 curObj = anUseCaseIter->Value();
348 if ( curObj->Tag() > theTag ) {
354 if ( !CORBA::is_nil( objAfter ))
355 useCaseBuilder->InsertBefore( SO, objAfter ); // insert at given tag
356 else if ( !isInUseCaseTree )
357 useCaseBuilder->AppendTo( theFatherObject, SO ); // append to the end of list
362 //=======================================================================
365 //=======================================================================
367 void SMESH_Gen_i::SetName(SALOMEDS::SObject_ptr theSObject,
369 const char* theDefaultName)
371 if ( !theSObject->_is_nil() ) {
372 SALOMEDS::StudyBuilder_var aStudyBuilder = getStudyServant()->NewBuilder();
373 SALOMEDS::GenericAttribute_wrap anAttr =
374 aStudyBuilder->FindOrCreateAttribute( theSObject, "AttributeName" );
375 SALOMEDS::AttributeName_wrap aNameAttr = anAttr;
376 if ( theName && theName[0] ) {
377 std::string name( theName ); // trim trailing white spaces
378 for ( size_t i = name.size()-1; i > 0; --i )
379 if ( isspace( name[i] )) name[i] = '\0';
381 aNameAttr->SetValue( name.c_str() );
385 CORBA::String_var curName = aNameAttr->Value();
386 if ( strlen( curName.in() ) == 0 ) {
387 SMESH_Comment aName(theDefaultName);
388 aNameAttr->SetValue( ( aName<< "_" << theSObject->Tag()).c_str() );
394 //=======================================================================
395 //function : SetPixMap
397 //=======================================================================
399 void SMESH_Gen_i::SetPixMap(SALOMEDS::SObject_ptr theSObject,
400 const char* thePixMap)
402 if ( !theSObject->_is_nil() && thePixMap && thePixMap && thePixMap[0] )
404 SALOMEDS::StudyBuilder_var aStudyBuilder = getStudyServant()->NewBuilder();
405 SALOMEDS::GenericAttribute_wrap anAttr =
406 aStudyBuilder->FindOrCreateAttribute( theSObject, "AttributePixMap" );
407 SALOMEDS::AttributePixMap_wrap aPMAttr = anAttr;
408 aPMAttr->SetPixMap( thePixMap );
412 //=======================================================================
413 //function : addReference
415 //=======================================================================
417 static void addReference (SALOMEDS::SObject_ptr theSObject,
418 CORBA::Object_ptr theToObject,
421 SALOMEDS::Study_var aStudy = SMESH_Gen_i::getStudyServant();
422 SALOMEDS::SObject_wrap aToObjSO = SMESH_Gen_i::ObjectToSObject( theToObject );
423 if ( !aToObjSO->_is_nil() && !theSObject->_is_nil() ) {
424 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
425 SALOMEDS::SObject_wrap aReferenceSO;
427 // check if the reference to theToObject already exists
428 // and find a free label for the reference object
429 bool isReferred = false;
431 SALOMEDS::ChildIterator_wrap anIter = aStudy->NewChildIterator( theSObject );
432 for ( ; !isReferred && anIter->More(); anIter->Next(), ++tag ) {
433 SALOMEDS::SObject_wrap curSO = anIter->Value();
434 if ( curSO->ReferencedObject( aReferenceSO.inout() )) {
435 CORBA::String_var refEntry = aReferenceSO->GetID();
436 CORBA::String_var toEntry = aToObjSO->GetID();
437 if ( strcmp( refEntry, toEntry ) == 0 )
440 else if ( !theTag ) {
441 SALOMEDS::GenericAttribute_wrap anAttr;
442 if ( !curSO->FindAttribute( anAttr.inout(), "AttributeIOR" ))
451 if ( !theSObject->FindSubObject( theTag, aReferenceSO.inout() ))
452 aReferenceSO = aStudyBuilder->NewObjectToTag( theSObject, theTag );
454 aStudyBuilder->Addreference( aReferenceSO, aToObjSO );
456 // make the reference visible (invisible ref is created by createInvalidSubMesh())
457 aStudyBuilder->RemoveAttribute( aReferenceSO, "AttributeDrawable" );
459 // add reference to the use case tree
460 // (to support tree representation customization and drag-n-drop)
461 SALOMEDS::UseCaseBuilder_wrap useCaseBuilder = aStudy->GetUseCaseBuilder();
462 SALOMEDS::UseCaseIterator_wrap useCaseIter = useCaseBuilder->GetUseCaseIterator(theSObject);
463 for ( ; useCaseIter->More(); useCaseIter->Next() )
465 SALOMEDS::SObject_wrap curSO = useCaseIter->Value();
466 if ( curSO->Tag() == theTag )
469 useCaseBuilder->AppendTo( theSObject, aReferenceSO );
473 //=============================================================================
475 * SMESH_Gen_i::PublishInStudy
477 * Publish object in the study
479 //=============================================================================
481 SALOMEDS::SObject_ptr SMESH_Gen_i::PublishInStudy(SALOMEDS::SObject_ptr theSObject,
482 CORBA::Object_ptr theIOR,
484 throw (SALOME::SALOME_Exception)
486 Unexpect aCatch(SALOME_SalomeException);
487 SALOMEDS::SObject_wrap aSO;
488 if ( !myIsEnablePublish )
490 if ( CORBA::is_nil( theIOR ))
492 if(MYDEBUG) MESSAGE("PublishInStudy");
495 SMESH::SMESH_Mesh_var aMesh = SMESH::SMESH_Mesh::_narrow( theIOR );
496 if( !aMesh->_is_nil() )
497 aSO = PublishMesh( aMesh, theName );
499 // Publishing a sub-mesh
500 SMESH::SMESH_subMesh_var aSubMesh = SMESH::SMESH_subMesh::_narrow( theIOR );
501 if( aSO->_is_nil() && !aSubMesh->_is_nil() ) {
502 GEOM::GEOM_Object_var aShapeObject = aSubMesh->GetSubShape();
503 aMesh = aSubMesh->GetFather();
504 aSO = PublishSubMesh( aMesh, aSubMesh, aShapeObject, theName );
507 // Publishing a hypothesis or algorithm
508 SMESH::SMESH_Hypothesis_var aHyp = SMESH::SMESH_Hypothesis::_narrow( theIOR );
509 if ( aSO->_is_nil() && !aHyp->_is_nil() )
510 aSO = PublishHypothesis( aHyp, theName );
512 // Publishing a group
513 SMESH::SMESH_GroupBase_var aGroup = SMESH::SMESH_GroupBase::_narrow(theIOR);
514 if ( aSO->_is_nil() && !aGroup->_is_nil() ) {
515 GEOM::GEOM_Object_var aShapeObject;
516 aMesh = aGroup->GetMesh();
517 aSO = PublishGroup( aMesh, aGroup, aShapeObject, theName );
519 if(MYDEBUG) MESSAGE("PublishInStudy_END");
524 //=======================================================================
525 //function : PublishComponent
527 //=======================================================================
529 SALOMEDS::SComponent_ptr SMESH_Gen_i::PublishComponent()
531 if(MYDEBUG) MESSAGE("PublishComponent");
532 if ( !myIsEnablePublish )
533 return SALOMEDS::SComponent::_nil();
535 SALOMEDS::StudyBuilder_var aStudyBuilder = getStudyServant()->NewBuilder();
536 SALOMEDS::UseCaseBuilder_wrap useCaseBuilder = getStudyServant()->GetUseCaseBuilder();
538 std::string compDataType = ComponentDataType(); // SMESH module's data type
539 std::string ior = SMESH_Gen_i::GetORB()->object_to_string( SMESH_Gen::_this() ); // IOR of this SMESH engine
541 // Find study component which corresponds to this SMESH engine
543 SALOMEDS::SComponent_wrap father;
544 SALOMEDS::SComponentIterator_wrap citer = getStudyServant()->NewComponentIterator();
545 for ( ; citer->More(); citer->Next()) {
546 SALOMEDS::SComponent_wrap f_i = citer->Value();
547 CORBA::String_var ior_i;
548 bool ok = f_i->ComponentIOR(ior_i.out());
549 if ( ok && compDataType == f_i->ComponentDataType() && ior == ior_i.in()) {
555 if ( !CORBA::is_nil( father ) ) {
556 // check that the component is added to the use case browser
557 if ( !useCaseBuilder->IsUseCaseNode( father ) ) {
558 useCaseBuilder->SetRootCurrent();
559 useCaseBuilder->Append( father ); // component object is added as the top level item
561 return father._retn();
564 // If component for this SMESH engine does not exist in the study, create it
566 SALOME_ModuleCatalog::ModuleCatalog_var aCat =
567 SALOME_ModuleCatalog::ModuleCatalog::_narrow( GetNS()->Resolve("/Kernel/ModulCatalog") );
568 if ( CORBA::is_nil( aCat ) )
569 return father._retn();
571 SALOME_ModuleCatalog::Acomponent_var aComp = aCat->GetComponent( compDataType.c_str() );
572 if ( CORBA::is_nil( aComp ) )
573 return father._retn();
575 SALOMEDS::GenericAttribute_wrap anAttr;
576 SALOMEDS::AttributePixMap_wrap aPixmap;
578 father = aStudyBuilder->NewComponent( compDataType.c_str() );
579 aStudyBuilder->DefineComponentInstance( father, SMESH_Gen::_this() );
580 anAttr = aStudyBuilder->FindOrCreateAttribute( father, "AttributePixMap" );
582 aPixmap->SetPixMap( "ICON_OBJBROWSER_SMESH" );
583 CORBA::String_var userName = aComp->componentusername();
584 SetName( father, userName.in(), "MESH" );
585 // add component to the use case tree
586 // (to support tree representation customization and drag-n-drop)
587 useCaseBuilder->SetRootCurrent();
588 useCaseBuilder->Append( father ); // component object is added as the top level item
589 if(MYDEBUG) MESSAGE("PublishComponent--END");
591 return father._retn();
594 //=======================================================================
595 //function : PublishMesh
597 //=======================================================================
599 SALOMEDS::SObject_ptr SMESH_Gen_i::PublishMesh (SMESH::SMESH_Mesh_ptr theMesh,
602 if ( !myIsEnablePublish )
603 return SALOMEDS::SObject::_nil();
604 if ( CORBA::is_nil( theMesh ))
605 return SALOMEDS::SObject::_nil();
606 if(MYDEBUG) MESSAGE("PublishMesh--IN");
608 // find or publish a mesh
610 SALOMEDS::SObject_wrap aMeshSO = ObjectToSObject( theMesh );
611 if ( aMeshSO->_is_nil() )
613 SALOMEDS::SComponent_wrap father = PublishComponent();
614 if ( father->_is_nil() )
615 return aMeshSO._retn();
617 // Find correct free tag
618 long aTag = father->GetLastChildTag();
619 if ( aTag <= GetAlgorithmsRootTag() )
620 aTag = GetAlgorithmsRootTag() + 1;
624 aMeshSO = publish( theMesh, father, aTag, "ICON_SMESH_TREE_MESH_WARN" );
625 if ( aMeshSO->_is_nil() )
626 return aMeshSO._retn();
628 SetName( aMeshSO, theName, "Mesh" );
630 // Add shape reference
632 GEOM::GEOM_Object_var aShapeObject = theMesh->GetShapeToMesh();
633 if ( !CORBA::is_nil( aShapeObject )) {
634 addReference( aMeshSO, aShapeObject, GetRefOnShapeTag() );
636 // Publish global hypotheses
638 SMESH::ListOfHypothesis_var hypList = theMesh->GetHypothesisList( aShapeObject );
639 for ( CORBA::ULong i = 0; i < hypList->length(); i++ )
641 SMESH::SMESH_Hypothesis_var aHyp = SMESH::SMESH_Hypothesis::_narrow( hypList[ i ]);
642 SALOMEDS::SObject_wrap so = PublishHypothesis( aHyp );
643 AddHypothesisToShape( theMesh, aShapeObject, aHyp );
649 SMESH_Mesh_i* mesh_i = objectToServant<SMESH_Mesh_i>( theMesh );
651 return aMeshSO._retn();
652 map<int, SMESH_subMesh_i*>& subMap = mesh_i->_mapSubMesh_i;
653 map<int, SMESH_subMesh_i*>::iterator subIt = subMap.begin();
654 for ( ; subIt != subMap.end(); subIt++ ) {
655 SMESH::SMESH_subMesh_ptr aSubMesh = (*subIt).second->_this();
656 if ( !CORBA::is_nil( aSubMesh )) {
657 aShapeObject = aSubMesh->GetSubShape();
658 SALOMEDS::SObject_wrap( PublishSubMesh( theMesh, aSubMesh, aShapeObject ));
663 const map<int, SMESH::SMESH_GroupBase_ptr>& grMap = mesh_i->getGroups();
664 map<int, SMESH::SMESH_GroupBase_ptr>::const_iterator it = grMap.begin();
665 for ( ; it != grMap.end(); it++ )
667 SMESH::SMESH_GroupBase_ptr aGroup = (*it).second;
668 if ( !aGroup->_is_nil() ) {
669 GEOM::GEOM_Object_var aShapeObj;
670 SMESH::SMESH_GroupOnGeom_var aGeomGroup = SMESH::SMESH_GroupOnGeom::_narrow( aGroup );
671 if ( !aGeomGroup->_is_nil() )
672 aShapeObj = aGeomGroup->GetShape();
673 SALOMEDS::SObject_wrap( PublishGroup( theMesh, aGroup, aShapeObj ));
677 if(MYDEBUG) MESSAGE("PublishMesh_END");
678 return aMeshSO._retn();
681 //=======================================================================
682 //function : PublishSubMesh
684 //=======================================================================
686 SALOMEDS::SObject_ptr SMESH_Gen_i::PublishSubMesh (SMESH::SMESH_Mesh_ptr theMesh,
687 SMESH::SMESH_subMesh_ptr theSubMesh,
688 GEOM::GEOM_Object_ptr theShapeObject,
691 if ( !myIsEnablePublish )
692 return SALOMEDS::SObject::_nil();
693 if ( theMesh->_is_nil() || theSubMesh->_is_nil() || theShapeObject->_is_nil() )
694 return SALOMEDS::SObject::_nil();
696 std::string newName( theName ? theName : "" );
698 SALOMEDS::SObject_wrap aSubMeshSO = ObjectToSObject( theSubMesh );
699 if ( aSubMeshSO->_is_nil() )
701 SALOMEDS::SObject_wrap aMeshSO = ObjectToSObject( theMesh );
702 if ( aMeshSO->_is_nil() ) {
703 aMeshSO = PublishMesh( theMesh );
704 if ( aMeshSO->_is_nil())
705 return SALOMEDS::SObject::_nil();
707 // Find submesh sub-tree tag
709 const char* aRootName = "";
710 switch ( theShapeObject->GetShapeType() ) {
712 aRootTag = GetSubMeshOnVertexTag();
713 aRootName = "SubMeshes on Vertex";
716 aRootTag = GetSubMeshOnEdgeTag();
717 aRootName = "SubMeshes on Edge";
720 aRootTag = GetSubMeshOnWireTag();
721 aRootName = "SubMeshes on Wire";
724 aRootTag = GetSubMeshOnFaceTag();
725 aRootName = "SubMeshes on Face";
728 aRootTag = GetSubMeshOnShellTag();
729 aRootName = "SubMeshes on Shell";
732 aRootTag = GetSubMeshOnSolidTag();
733 aRootName = "SubMeshes on Solid";
736 aRootTag = GetSubMeshOnCompoundTag();
737 aRootName = "SubMeshes on Compound";
741 // Find or create submesh root
742 SALOMEDS::SObject_wrap aRootSO = publish ( CORBA::Object::_nil(),
743 aMeshSO, aRootTag, 0, false );
744 if ( aRootSO->_is_nil() )
745 return aSubMeshSO._retn();
747 SetName( aRootSO, aRootName );
749 // Add new sub-mesh to corresponding sub-tree
750 int tag = 0; // to use a new SObject
751 if ( theName && theName[0] == '0' )
753 // theName can be an entry of an invalid sub-mesh which theSubMesh should replace
754 SALOMEDS::SObject_wrap aSObj = getStudyServant()->FindObjectID( theName );
757 CORBA::String_var oldName = aSObj->GetName();
758 newName = oldName.in();
759 SALOMEDS::SObject_wrap aRootSO2 = aSObj->GetFather();
760 if ( aRootSO->Tag() == aRootSO2->Tag() ) // same parent
761 tag = aSObj->Tag(); // to use the same SObject
764 CORBA::Object_var anObj = SObjectToObject( aSObj );
765 SMESH::SMESH_subMesh_var sm = SMESH::SMESH_subMesh::_narrow( anObj );
766 theMesh->RemoveSubMesh( sm );
770 SMESH::array_of_ElementType_var elemTypes = theSubMesh->GetTypes();
771 const int isEmpty = ( elemTypes->length() == 0 );
772 const char* pm[2] = { "ICON_SMESH_TREE_MESH", "ICON_SMESH_TREE_MESH_WARN" };
773 aSubMeshSO = publish ( theSubMesh, aRootSO, tag, pm[isEmpty] );
774 if ( aSubMeshSO->_is_nil() )
775 return aSubMeshSO._retn();
777 highLightInvalid( aSubMeshSO, false ); // now it is valid
779 SetName( aSubMeshSO, newName.c_str(), "SubMesh" );
781 // Add reference to theShapeObject
783 addReference( aSubMeshSO, theShapeObject, GetRefOnShapeTag() );
785 // Publish hypothesis
787 SMESH::ListOfHypothesis_var hypList = theMesh->GetHypothesisList( theShapeObject );
788 for ( CORBA::ULong i = 0; i < hypList->length(); i++ )
790 SMESH::SMESH_Hypothesis_var aHyp = SMESH::SMESH_Hypothesis::_narrow( hypList[ i ]);
791 SALOMEDS::SObject_wrap so = PublishHypothesis( aHyp );
792 AddHypothesisToShape( theMesh, theShapeObject, aHyp );
795 return aSubMeshSO._retn();
798 //=======================================================================
799 //function : PublishGroup
801 //=======================================================================
803 SALOMEDS::SObject_ptr SMESH_Gen_i::PublishGroup (SMESH::SMESH_Mesh_ptr theMesh,
804 SMESH::SMESH_GroupBase_ptr theGroup,
805 GEOM::GEOM_Object_ptr theShapeObject,
808 if ( !myIsEnablePublish )
809 return SALOMEDS::SObject::_nil();
810 if (theMesh->_is_nil() || theGroup->_is_nil() )
811 return SALOMEDS::SObject::_nil();
813 SALOMEDS::SObject_wrap aGroupSO = ObjectToSObject( theGroup );
814 if ( aGroupSO->_is_nil() )
816 SALOMEDS::SObject_wrap aMeshSO = ObjectToSObject( theMesh );
817 if ( aMeshSO->_is_nil() ) {
818 aMeshSO = PublishInStudy( SALOMEDS::SObject::_nil(), theMesh, "");
819 if ( aMeshSO->_is_nil())
820 return SALOMEDS::SObject::_nil();
822 size_t aType = (int)theGroup->GetType();
823 const char* aRootNames[] = {
824 "Compound Groups", "Groups of Nodes", "Groups of Edges",
825 "Groups of Faces", "Groups of Volumes", "Groups of 0D Elements",
828 // Currently, groups with heterogeneous content are not supported
829 if ( aType != SMESH::ALL )
831 long aRootTag = GetNodeGroupsTag() + aType - 1;
833 // Find or create groups root
834 SALOMEDS::SObject_wrap aRootSO = publish ( CORBA::Object::_nil(),
835 aMeshSO, aRootTag, 0, false );
836 if ( aRootSO->_is_nil() ) return SALOMEDS::SObject::_nil();
838 if ( aType < sizeof(aRootNames)/sizeof(char*) )
839 SetName( aRootSO, aRootNames[aType] );
841 // Add new group to corresponding sub-tree
843 std::string pm[2] = { "ICON_SMESH_TREE_GROUP", "ICON_SMESH_TREE_MESH_WARN" };
844 if ( SMESH::DownCast< SMESH_GroupOnFilter_i* > ( theGroup ))
846 pm[0] = "ICON_SMESH_TREE_GROUP_ON_FILTER";
848 else if ( SMESH::DownCast< SMESH_Group_i* > ( theGroup ))
850 if ( theGroup->GetType() == SMESH::NODE )
851 isEmpty = ( theMesh->NbNodes() == 0 );
854 SMESH::array_of_ElementType_var allElemTypes = theMesh->GetTypes();
855 for ( size_t i =0; i < allElemTypes->length() && isEmpty; ++i )
856 isEmpty = ( allElemTypes[i] != theGroup->GetType() );
859 aGroupSO = publish ( theGroup, aRootSO, 0, pm[isEmpty].c_str() );
861 if ( aGroupSO->_is_nil() )
862 return aGroupSO._retn();
865 SetName( aGroupSO, theName, "Group" );
867 //Add reference to geometry
868 if ( !theShapeObject->_is_nil() )
869 addReference( aGroupSO, theShapeObject, GetRefOnShapeTag() );
871 return aGroupSO._retn();
874 //=======================================================================
875 //function : PublishHypothesis
877 //=======================================================================
879 SALOMEDS::SObject_ptr
880 SMESH_Gen_i::PublishHypothesis (SMESH::SMESH_Hypothesis_ptr theHyp,
883 if(MYDEBUG) MESSAGE("PublishHypothesis")
884 if ( !myIsEnablePublish )
885 return SALOMEDS::SObject::_nil();
886 if (theHyp->_is_nil())
887 return SALOMEDS::SObject::_nil();
889 CORBA::String_var hypType = theHyp->GetName();
891 SALOMEDS::SObject_wrap aHypSO = ObjectToSObject( theHyp );
892 if ( aHypSO->_is_nil() )
894 SALOMEDS::SComponent_wrap father = PublishComponent();
895 if ( father->_is_nil() )
896 return aHypSO._retn();
898 //Find or Create Hypothesis root
899 bool isAlgo = ( !SMESH::SMESH_Algo::_narrow( theHyp )->_is_nil() );
900 int aRootTag = isAlgo ? GetAlgorithmsRootTag() : GetHypothesisRootTag();
901 SALOMEDS::SObject_wrap aRootSO =
902 publish (CORBA::Object::_nil(),father, aRootTag,
903 isAlgo ? "ICON_SMESH_TREE_ALGO" : "ICON_SMESH_TREE_HYPO", false);
904 SetName( aRootSO, isAlgo ? "Algorithms" : "Hypotheses" );
906 // Add New Hypothesis
907 string aPmName = isAlgo ? "ICON_SMESH_TREE_ALGO_" : "ICON_SMESH_TREE_HYPO_";
908 aPmName += hypType.in();
909 // prepend plugin name to pixmap name
910 string pluginName = myHypCreatorMap[ hypType.in() ]->GetModuleName();
911 if ( pluginName != "StdMeshers" )
912 aPmName = pluginName + "::" + aPmName;
913 aHypSO = publish( theHyp, aRootSO, 0, aPmName.c_str() );
916 SetName( aHypSO, theName, hypType.in() );
918 if(MYDEBUG) MESSAGE("PublishHypothesis--END")
919 return aHypSO._retn();
922 //=======================================================================
923 //function : UpdateIcons
924 //purpose : update icons of a mesh and its children upon mesh modification
925 //=======================================================================
927 void SMESH_Gen_i::UpdateIcons( SMESH::SMESH_Mesh_ptr theMesh )
929 SMESH_Mesh_i* mesh_i = SMESH::DownCast< SMESH_Mesh_i* >( theMesh );
933 SALOMEDS::SObject_wrap so = ObjectToSObject( theMesh );
937 // set icon of the mesh
938 if ( mesh_i->NbNodes() == 0 )
939 SetPixMap( so, "ICON_SMESH_TREE_MESH_WARN" );
940 else if ( mesh_i->IsComputedOK() )
941 SetPixMap( so, "ICON_SMESH_TREE_MESH" );
942 else if ( mesh_i->HasShapeToMesh() )
943 SetPixMap( so, "ICON_SMESH_TREE_MESH_PARTIAL" );
945 SetPixMap( so, "ICON_SMESH_TREE_MESH_IMPORTED" );
947 // set icons of sub-objects
948 SALOMEDS::Study_var study = getStudyServant();
949 SALOMEDS::ChildIterator_wrap iter = study->NewChildIterator( so );
950 for ( ; iter->More(); iter->Next() )
952 so = iter->Value(); // 1st level child - root of algos, hyps, sub-meshes or groups
953 if ( so->Tag() < SMESH::Tag_FirstSubMesh )
956 SALOMEDS::ChildIterator_wrap subIter = study->NewChildIterator( so );
957 for ( ; subIter->More(); subIter->Next() )
959 so = subIter->Value(); // 2nd level child - a sub-mesh or group
961 CORBA::Object_var obj = SObjectToObject( so );
962 SMESH::SMESH_IDSource_var idSrc = SMESH::SMESH_IDSource::_narrow( obj );
963 if ( idSrc->_is_nil() )
966 SMESH::SMESH_GroupBase_var grp = SMESH::SMESH_GroupBase::_narrow( obj );
967 SMESH::SMESH_GroupOnFilter_var gof = SMESH::SMESH_GroupOnFilter::_narrow( obj );
968 const bool isGroup = !grp->_is_nil();
969 const bool isGroupOnFilter = !gof->_is_nil();
971 bool isEmpty = ( mesh_i->NbNodes() == 0 );
974 if ( isGroupOnFilter ) // GetTypes() can be very long on GroupOnFilter!
976 SMESH::long_array_var nbByType = mesh_i->GetNbElementsByType();
977 isEmpty = ( nbByType[ grp->GetType() ] == 0 );
981 SMESH::array_of_ElementType_var elemTypes = idSrc->GetTypes();
982 isEmpty = ( elemTypes->length() == 0 );
986 SetPixMap( so, "ICON_SMESH_TREE_MESH_WARN");
988 SetPixMap( so, "ICON_SMESH_TREE_MESH" );
989 else if ( isGroupOnFilter )
990 SetPixMap( so, "ICON_SMESH_TREE_GROUP_ON_FILTER" );
992 SetPixMap( so, "ICON_SMESH_TREE_GROUP" );
997 //=======================================================================
998 //function : HighLightInvalid
999 //purpose : change font color of a object in the Object Browser
1000 //=======================================================================
1002 void SMESH_Gen_i::HighLightInvalid( CORBA::Object_ptr theObject, bool isInvalid )
1004 SALOMEDS::SObject_wrap so = ObjectToSObject(theObject);
1005 highLightInvalid( so.in(), isInvalid );
1008 //=======================================================================
1009 //function : highLightInvalid
1010 //purpose : change font color of a object in the Object Browser
1011 //=======================================================================
1013 void SMESH_Gen_i::highLightInvalid( SALOMEDS::SObject_ptr theSObject, bool isInvalid )
1015 if ( !theSObject->_is_nil() )
1017 SALOMEDS::StudyBuilder_var studyBuilder = getStudyServant()->NewBuilder();
1020 SALOMEDS::Color red = { 178,34,34 }; // to differ from reference color
1021 SALOMEDS::GenericAttribute_wrap attr =
1022 studyBuilder->FindOrCreateAttribute( theSObject, "AttributeTextColor" );
1023 SALOMEDS::AttributeTextColor_wrap colorAttr = attr;
1024 colorAttr->SetTextColor( red );
1028 studyBuilder->RemoveAttribute( theSObject, "AttributeTextColor" );
1033 //=======================================================================
1034 //function : GetMeshOrSubmeshByShape
1036 //=======================================================================
1038 SALOMEDS::SObject_ptr
1039 SMESH_Gen_i::GetMeshOrSubmeshByShape (SMESH::SMESH_Mesh_ptr theMesh,
1040 GEOM::GEOM_Object_ptr theShape)
1042 if(MYDEBUG) MESSAGE("GetMeshOrSubmeshByShape")
1043 SALOMEDS::SObject_wrap aMeshOrSubMesh;
1044 if (theMesh->_is_nil() || ( theShape->_is_nil() && theMesh->HasShapeToMesh()))
1045 return aMeshOrSubMesh._retn();
1047 TopoDS_Shape aShape;
1048 if(theMesh->HasShapeToMesh())
1049 aShape = GeomObjectToShape( theShape );
1051 aShape = SMESH_Mesh::PseudoShape();
1053 SMESH_Mesh_i* mesh_i = objectToServant<SMESH_Mesh_i>( theMesh );
1055 if ( !aShape.IsNull() && mesh_i && mesh_i->GetImpl().GetMeshDS() ) {
1056 SMESHDS_Mesh* meshDS = mesh_i->GetImpl().GetMeshDS();
1057 if ( aShape.IsSame( meshDS->ShapeToMesh() ))
1058 aMeshOrSubMesh = ObjectToSObject( theMesh );
1060 int shapeID = meshDS->ShapeToIndex( aShape );
1061 SMESH::SMESH_subMesh_var aSubMesh = mesh_i->getSubMesh(shapeID);
1062 if ( !aSubMesh->_is_nil() )
1063 aMeshOrSubMesh = ObjectToSObject( aSubMesh );
1066 if(MYDEBUG) MESSAGE("GetMeshOrSubmeshByShape--END")
1067 return aMeshOrSubMesh._retn();
1070 //=======================================================================
1071 //function : AddHypothesisToShape
1073 //=======================================================================
1075 bool SMESH_Gen_i::AddHypothesisToShape(SMESH::SMESH_Mesh_ptr theMesh,
1076 GEOM::GEOM_Object_ptr theShape,
1077 SMESH::SMESH_Hypothesis_ptr theHyp)
1079 if(MYDEBUG) MESSAGE("AddHypothesisToShape")
1080 if (theMesh->_is_nil() ||
1081 theHyp->_is_nil() || (theShape->_is_nil()
1082 && theMesh->HasShapeToMesh()) )
1085 SALOMEDS::SObject_wrap aMeshSO = ObjectToSObject( theMesh );
1086 if ( aMeshSO->_is_nil() )
1087 aMeshSO = PublishMesh( theMesh );
1088 SALOMEDS::SObject_wrap aHypSO = PublishHypothesis( theHyp );
1089 if ( aMeshSO->_is_nil() || aHypSO->_is_nil())
1092 // Find a mesh or submesh referring to theShape
1093 SALOMEDS::SObject_wrap aMeshOrSubMesh =
1094 GetMeshOrSubmeshByShape( theMesh, theShape );
1095 if ( aMeshOrSubMesh->_is_nil() )
1098 TopoDS_Shape aShape = GeomObjectToShape( theShape );
1099 SMESH_Mesh_i* mesh_i = objectToServant<SMESH_Mesh_i>( theMesh );
1100 if ( !aShape.IsNull() && mesh_i && mesh_i->GetImpl().GetMeshDS() ) {
1101 SMESHDS_Mesh* meshDS = mesh_i->GetImpl().GetMeshDS();
1102 int shapeID = meshDS->ShapeToIndex( aShape );
1103 SMESH::SMESH_subMesh_var aSubMesh = mesh_i->getSubMesh(shapeID);
1104 aMeshOrSubMesh = PublishSubMesh( theMesh, aSubMesh, theShape );
1106 if ( aMeshOrSubMesh->_is_nil() )
1110 //Find or Create Applied Hypothesis root
1111 bool aIsAlgo = !SMESH::SMESH_Algo::_narrow( theHyp )->_is_nil();
1112 SALOMEDS::SObject_wrap AHR =
1113 publish (CORBA::Object::_nil(), aMeshOrSubMesh,
1114 aIsAlgo ? GetRefOnAppliedAlgorithmsTag() : GetRefOnAppliedHypothesisTag(),
1115 aIsAlgo ? "ICON_SMESH_TREE_ALGO" : "ICON_SMESH_TREE_HYPO", false);
1116 SetName( AHR, aIsAlgo ? "Applied algorithms" : "Applied hypotheses" );
1118 addReference( AHR, theHyp );
1120 if(MYDEBUG) MESSAGE("AddHypothesisToShape--END")
1124 //=======================================================================
1125 //function : RemoveHypothesisFromShape
1127 //=======================================================================
1129 bool SMESH_Gen_i::RemoveHypothesisFromShape(SMESH::SMESH_Mesh_ptr theMesh,
1130 GEOM::GEOM_Object_ptr theShape,
1131 SMESH::SMESH_Hypothesis_ptr theHyp)
1133 if (theMesh->_is_nil() ||
1134 theHyp->_is_nil() || (theShape->_is_nil()
1135 && theMesh->HasShapeToMesh()))
1138 SALOMEDS::SObject_wrap aHypSO = ObjectToSObject( theHyp );
1139 if ( aHypSO->_is_nil() )
1142 CORBA::String_var hypEntry = aHypSO->GetID();
1144 // Find a mesh or sub-mesh referring to theShape
1145 SALOMEDS::SObject_wrap aMeshOrSubMesh =
1146 GetMeshOrSubmeshByShape( theMesh, theShape );
1147 if ( aMeshOrSubMesh->_is_nil() )
1150 // Find and remove a reference to aHypSO
1151 SALOMEDS::SObject_wrap aRef, anObj;
1152 SALOMEDS::ChildIterator_wrap it = getStudyServant()->NewChildIterator( aMeshOrSubMesh );
1154 for ( it->InitEx( true ); ( it->More() && !found ); it->Next() ) {
1155 anObj = it->Value();
1156 if (anObj->ReferencedObject( aRef.inout() ))
1158 CORBA::String_var refEntry = aRef->GetID();
1159 found = ( strcmp( refEntry, hypEntry ) == 0 );
1163 SALOMEDS::StudyBuilder_var builder = getStudyServant()->NewBuilder();
1164 builder->RemoveObject( anObj );
1171 //================================================================================
1173 * \brief Stores names of variables that WILL be passes as parameters when calling
1174 * some method of a given object.
1175 * \param [in] theObject - the object whose a method WILL be called with \a theParameters.
1176 * \param [in] theParameters - a string containing parameters separated by ':'.
1178 //================================================================================
1180 void SMESH_Gen_i::UpdateParameters(CORBA::Object_ptr theObject, const char* theParameters)
1182 // find variable names within theParameters
1185 myLastParameters.clear();
1186 myLastParamIndex.clear(); /* vector holding indices of virables within the string
1187 of all variables used for theObject */
1189 int pos = 0, prevPos = 0, len = strlen( theParameters );
1190 if ( len == 0 ) return;
1191 while ( pos <= len )
1193 if ( pos == len || theParameters[pos] == ':' )
1195 if ( prevPos < pos )
1197 string val( theParameters + prevPos, theParameters + pos );
1198 if ( !getStudyServant()->IsVariable( val.c_str() ))
1200 myLastParameters.push_back( val );
1201 nbVars += (! myLastParameters.back().empty() );
1205 myLastParameters.push_back("");
1216 // (1) variable names in the string of all variables used for theObject and
1217 // (2) indices of found variables in myLastParamIndex.
1219 // remember theObject
1220 SALOMEDS::SObject_wrap aSObj = ObjectToSObject(theObject);
1221 if ( aSObj->_is_nil() )
1223 CORBA::String_var anObjEntry = aSObj->GetID();
1224 myLastObj = anObjEntry.in();
1226 // get a string of variable names
1227 SALOMEDS::StudyBuilder_var aStudyBuilder = getStudyServant()->NewBuilder();
1228 SALOMEDS::GenericAttribute_wrap anAttr =
1229 aStudyBuilder->FindOrCreateAttribute( aSObj, "AttributeString" );
1230 SALOMEDS::AttributeString_wrap aStringAttr = anAttr;
1231 CORBA::String_var oldVars = aStringAttr->Value();
1232 std::string varStr = oldVars.in();
1234 // add new variables and find indices of variables
1235 for ( size_t i = 0; i < myLastParameters.size(); ++i )
1238 if ( !myLastParameters[i].empty() )
1240 // find index of myLastParameters[i] in varStr
1242 bool varFound = false;
1244 // varStr can be "A|B::C;*=2|D"
1245 const std::string separators(":|;*=");
1246 while ( pos < varStr.size() && !varFound )
1249 while ( separators.find( varStr[ pos ]) != std::string::npos )
1250 if ( ++pos >= varStr.size() )
1252 // skip repetition number following '='
1253 if ( varStr[ pos-1 ] == '=' )
1255 while ( '0' <= varStr[ pos ] && varStr[ pos ] <= '9' )
1257 continue; // to skip next separator
1259 // compare variable name
1260 if ( pos < varStr.size() )
1262 varFound = ( varStr.compare( pos, myLastParameters[i].size(), myLastParameters[i] ) == 0 &&
1263 // same string beginning but is length same?
1264 ( pos + myLastParameters[i].size() >= varStr.size() ||
1265 separators.find( varStr[ pos+1 ]) != std::string::npos ));
1267 varIndex = curIndex;
1269 pos = varStr.find_first_of( separators, pos ); // goto the next separator
1276 varStr += ":" + myLastParameters[i];
1277 varIndex = curIndex;
1280 myLastParamIndex.push_back( varIndex );
1282 aStringAttr->SetValue( varStr.c_str() );
1285 //================================================================================
1287 * \brief Return all variables used to create an object
1288 * \param [in] theObjectEntry - an object entry in the current study
1289 * \return std::vector< std::string > - all variable names (or values of removed variables)
1291 //================================================================================
1293 std::vector< std::string > SMESH_Gen_i::GetAllParameters(const std::string& theObjectEntry) const
1295 std::vector< std::string > varNames;
1297 SALOMEDS::SObject_wrap aSObj = getStudyServant()->FindObjectID( theObjectEntry.c_str() );
1299 // get a string of variable names
1300 SALOMEDS::StudyBuilder_var aStudyBuilder = getStudyServant()->NewBuilder();
1301 SALOMEDS::GenericAttribute_wrap anAttr =
1302 aStudyBuilder->FindOrCreateAttribute( aSObj, "AttributeString" );
1303 SALOMEDS::AttributeString_wrap aStringAttr = anAttr;
1304 CORBA::String_var oldVars = aStringAttr->Value();
1305 std::string varStr = oldVars.in();
1307 // separate variables within varStr;
1308 // varStr can be "A|B::C;*=2|D"
1310 const std::string separators(":|;*=");
1311 while ( pos < varStr.size() )
1314 pos = varStr.find_first_not_of( separators, pos );
1315 // while ( separators.find( varStr[ pos ]) != std::string::npos )
1316 // if ( ++pos >= varStr.size() )
1318 // skip repetition number following '='
1319 if ( varStr[ pos-1 ] == '=' )
1321 while ( '0' <= varStr[ pos ] && varStr[ pos ] <= '9' )
1323 continue; // to skip next separator
1325 // store variable name
1326 if ( pos < varStr.size() )
1328 size_t pos2 = varStr.find_first_of( separators, pos );
1329 varNames.push_back( varStr.substr( pos, pos2 - pos));
1336 //=======================================================================
1337 //function : ParseParameters
1338 //purpose : Replace variables by their values
1339 //=======================================================================
1340 // char* SMESH_Gen_i::ParseParameters(const char* theParameters)
1342 // //const char* aParameters = theParameters;
1343 // // const char* aParameters = CORBA::string_dup(theParameters);
1344 // TCollection_AsciiString anInputParams;
1345 // SALOMEDS::Study_var aStudy = getStudyServant();
1346 // if( !aStudy->_is_nil() ) {
1347 // // SALOMEDS::ListOfListOfStrings_var aSections = aStudy->ParseVariables(theParameters);
1348 // // for(int j=0;j<aSections->length();j++) {
1349 // // SALOMEDS::ListOfStrings aVars= aSections[j];
1350 // // for(int i=0;i<aVars.length();i++ ) {
1351 // // anInputParams += aStudy->IsVariable(aVars[i].in()) ?
1352 // // TCollection_AsciiString(aVars[i].in()) : TCollection_AsciiString("");
1353 // // if(i != aVars.length()-1)
1354 // // anInputParams+=":";
1356 // // if(j!=aSections->length()-1)
1357 // // anInputParams+="|";
1359 // TCollection_AsciiString paramStr( theParameters );
1360 // int beg = 0, end;
1361 // char sep, *pParams = (char*)paramStr.ToCString();
1362 // while ( beg < paramStr.Length() )
1365 // while ( ++end < paramStr.Length() )
1366 // if ( pParams[end] == ':' || pParams[end] == '|')
1368 // if ( end < paramStr.Length())
1370 // sep = pParams[end];
1371 // pParams[end] = '\0';
1373 // if ( aStudy->IsVariable( pParams+beg ))
1374 // anInputParams += pParams+beg;
1375 // if ( end < paramStr.Length() )
1376 // anInputParams += sep;
1382 // return CORBA::string_dup(anInputParams.ToCString());
1385 //=======================================================================
1386 //function : GetParameters
1388 //=======================================================================
1390 char* SMESH_Gen_i::GetParameters(CORBA::Object_ptr theObject)
1392 CORBA::String_var aResult("");
1394 SALOMEDS::SObject_wrap aSObj = ObjectToSObject( theObject );
1395 if ( !aSObj->_is_nil() )
1397 SALOMEDS::GenericAttribute_wrap attr;
1398 if ( aSObj->FindAttribute( attr.inout(), "AttributeString"))
1400 SALOMEDS::AttributeString_wrap strAttr = attr;
1401 aResult = strAttr->Value();
1404 return aResult._retn();
1407 //================================================================================
1409 * \brief Create a sub-mesh on a geometry that is not a sub-shape of the main shape
1410 * for the case where a valid sub-shape not found by CopyMeshWithGeom().
1411 * The invalid sub-mesh has GetId() < 0.
1413 //================================================================================
1415 SMESH::SMESH_subMesh_ptr
1416 SMESH_Gen_i::createInvalidSubMesh(SMESH::SMESH_Mesh_ptr theMesh,
1417 GEOM::GEOM_Object_ptr theStrangerGeom,
1418 const char* theName)
1420 SMESH::SMESH_subMesh_var subMesh;
1424 SMESH_Mesh_i* mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( theMesh );
1425 subMesh = mesh_i->createSubMesh( theStrangerGeom );
1427 if ( !subMesh->_is_nil() && CanPublishInStudy( subMesh ))
1429 SALOMEDS::SObject_wrap so = PublishSubMesh( theMesh, subMesh, theStrangerGeom, theName );
1431 // hide a reference to geometry
1432 if ( !so->_is_nil() )
1434 SALOMEDS::SObject_wrap refSO;
1435 if ( so->FindSubObject( GetRefOnShapeTag(), refSO.inout() ))
1437 SALOMEDS::StudyBuilder_var studyBuilder = getStudyServant()->NewBuilder();
1438 SALOMEDS::GenericAttribute_wrap attr =
1439 studyBuilder->FindOrCreateAttribute( refSO, "AttributeDrawable" );
1440 SALOMEDS::AttributeDrawable_wrap ga = attr;
1441 ga->SetDrawable( false );
1449 return subMesh._retn();
1457 //=======================================================================
1458 //function : addObject
1459 //purpose : register object in the internal map and return its id
1460 //=======================================================================
1462 int StudyContext::addObject( const std::string& theIOR )
1464 int nextId = getNextId();
1465 mapIdToIOR.Bind( nextId, theIOR );
1469 //=======================================================================
1471 //purpose : find the object id in the internal map by the IOR
1472 //=======================================================================
1474 int StudyContext::findId( const std::string& theIOR )
1476 TInt2StringMap::iterator imap;
1477 for ( imap = mapIdToIOR.begin(); imap != mapIdToIOR.end(); ++imap ) {
1478 if ( *imap == theIOR )
1479 return imap.Iterator().Key();
1484 //=======================================================================
1485 //function : getIORbyId
1486 //purpose : get object's IOR by id
1487 //=======================================================================
1489 std::string StudyContext::getIORbyId( const int theId )
1491 if ( mapIdToIOR.IsBound( theId ) )
1492 return mapIdToIOR( theId );
1493 return std::string();
1496 //=======================================================================
1497 //function : getIORbyOldId
1498 //purpose : get object's IOR by old id
1499 //=======================================================================
1501 std::string StudyContext::getIORbyOldId( const int theOldId )
1503 if ( mapIdToId.IsBound( theOldId ) )
1504 return getIORbyId( mapIdToId( theOldId ));
1505 return std::string();
1508 //=======================================================================
1509 //function : mapOldToNew
1510 //purpose : maps old object id to the new one (used when restoring data)
1511 //=======================================================================
1513 void StudyContext::mapOldToNew( const int oldId, const int newId )
1515 mapIdToId.Bind( oldId, newId );
1518 //=======================================================================
1519 //function : getOldId
1520 //purpose : get old id by a new one
1521 //=======================================================================
1523 int StudyContext::getOldId( const int newId )
1525 TInt2IntMap::iterator imap;
1526 for ( imap = mapIdToId.begin(); imap != mapIdToId.end(); ++imap ) {
1527 if ( *imap == newId )
1528 return imap.Iterator().Key();
1533 //=======================================================================
1535 //purpose : clear data
1536 //=======================================================================
1538 void StudyContext::Clear()