1 // SMESH SMESH_I : idl implementation based on 'SMESH' unit's calsses
3 // Copyright (C) 2003 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.
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
23 // File : SMESH_Gen_i_1.cxx
24 // Created : Thu Oct 21 17:24:06 2004
25 // Author : Edward AGAPOV (eap)
29 #include "SMESH_Gen_i.hxx"
31 #include "SMESH_Mesh_i.hxx"
32 #include "SMESH_Hypothesis_i.hxx"
33 #include "SMESH_Algo_i.hxx"
34 #include "SMESH_Group_i.hxx"
38 #include CORBA_CLIENT_HEADER(SALOME_ModuleCatalog)
40 #include "utilities.h"
41 #include "Utils_ExceptHandlers.hxx"
43 #include <TCollection_AsciiString.hxx>
46 static int MYDEBUG = 0;
48 static int MYDEBUG = 0;
51 //=============================================================================
53 * Get...Tag [ static ]
55 * Methods which determine SMESH data model structure
57 //=============================================================================
59 long SMESH_Gen_i::GetHypothesisRootTag()
61 return Tag_HypothesisRoot;
64 long SMESH_Gen_i::GetAlgorithmsRootTag()
66 return Tag_AlgorithmsRoot;
69 long SMESH_Gen_i::GetRefOnShapeTag()
71 return Tag_RefOnShape;
74 long SMESH_Gen_i::GetRefOnAppliedHypothesisTag()
76 return Tag_RefOnAppliedHypothesis;
79 long SMESH_Gen_i::GetRefOnAppliedAlgorithmsTag()
81 return Tag_RefOnAppliedAlgorithms;
84 long SMESH_Gen_i::GetSubMeshOnVertexTag()
86 return Tag_SubMeshOnVertex;
89 long SMESH_Gen_i::GetSubMeshOnEdgeTag()
91 return Tag_SubMeshOnEdge;
94 long SMESH_Gen_i::GetSubMeshOnFaceTag()
96 return Tag_SubMeshOnFace;
99 long SMESH_Gen_i::GetSubMeshOnSolidTag()
101 return Tag_SubMeshOnSolid;
104 long SMESH_Gen_i::GetSubMeshOnCompoundTag()
106 return Tag_SubMeshOnCompound;
109 long SMESH_Gen_i::GetSubMeshOnWireTag()
111 return Tag_SubMeshOnWire;
114 long SMESH_Gen_i::GetSubMeshOnShellTag()
116 return Tag_SubMeshOnShell;
119 long SMESH_Gen_i::GetNodeGroupsTag()
121 return Tag_NodeGroups;
124 long SMESH_Gen_i::GetEdgeGroupsTag()
126 return Tag_EdgeGroups;
129 long SMESH_Gen_i::GetFaceGroupsTag()
131 return Tag_FaceGroups;
134 long SMESH_Gen_i::GetVolumeGroupsTag()
136 return Tag_VolumeGroups;
139 //=============================================================================
141 * SMESH_Gen_i::CanPublishInStudy
143 * Returns true if object can be published in the study
145 //=============================================================================
147 bool SMESH_Gen_i::CanPublishInStudy(CORBA::Object_ptr theIOR)
149 if(MYDEBUG) MESSAGE("CanPublishInStudy - "<<!CORBA::is_nil(myCurrentStudy));
150 if(CORBA::is_nil(myCurrentStudy))
153 SMESH::SMESH_Mesh_var aMesh = SMESH::SMESH_Mesh::_narrow(theIOR);
154 if( !aMesh->_is_nil() )
157 SMESH::SMESH_subMesh_var aSubMesh = SMESH::SMESH_subMesh::_narrow(theIOR);
158 if( !aSubMesh->_is_nil() )
161 SMESH::SMESH_Hypothesis_var aHyp = SMESH::SMESH_Hypothesis::_narrow(theIOR);
162 if( !aHyp->_is_nil() )
165 SMESH::SMESH_GroupBase_var aGroup = SMESH::SMESH_GroupBase::_narrow(theIOR);
166 if( !aGroup->_is_nil() )
169 if(MYDEBUG) MESSAGE("CanPublishInStudy--CANT");
173 //=======================================================================
174 //function : ObjectToSObject
176 //=======================================================================
178 SALOMEDS::SObject_ptr SMESH_Gen_i::ObjectToSObject(SALOMEDS::Study_ptr theStudy,
179 CORBA::Object_ptr theObject)
181 SALOMEDS::SObject_var aSO;
182 if ( !CORBA::is_nil( theStudy ) && !CORBA::is_nil( theObject ))
183 aSO = theStudy->FindObjectIOR( SMESH_Gen_i::GetORB()->object_to_string( theObject ) );
187 //=======================================================================
188 //function : objectToServant
190 //=======================================================================
192 template<typename T> static inline T* objectToServant( CORBA::Object_ptr theIOR )
194 return dynamic_cast<T*>( SMESH_Gen_i::GetServant( theIOR ).in() );
197 //=======================================================================
198 //function : ShapeToGeomObject
200 //=======================================================================
202 GEOM::GEOM_Object_ptr SMESH_Gen_i::ShapeToGeomObject (const TopoDS_Shape& theShape )
204 GEOM::GEOM_Object_var aShapeObj;
205 if ( !theShape.IsNull() ) {
206 GEOM_Client* aClient = GetShapeReader();
207 TCollection_AsciiString IOR;
208 if ( aClient && aClient->Find( theShape, IOR ))
209 aShapeObj = GEOM::GEOM_Object::_narrow
210 ( GetORB()->string_to_object( IOR.ToCString() ) );
212 return aShapeObj._retn();
215 //=======================================================================
216 //function : GeomObjectToShape
218 //=======================================================================
220 TopoDS_Shape SMESH_Gen_i::GeomObjectToShape(GEOM::GEOM_Object_ptr theGeomObject)
223 if ( !theGeomObject->_is_nil() ) {
224 GEOM_Client* aClient = GetShapeReader();
225 GEOM::GEOM_Gen_var aGeomEngine = GetGeomEngine();
226 if ( aClient && !aGeomEngine->_is_nil () )
227 S = aClient->GetShape( aGeomEngine, theGeomObject );
232 //=======================================================================
235 //=======================================================================
237 static SALOMEDS::SObject_ptr publish(SALOMEDS::Study_ptr theStudy,
238 CORBA::Object_ptr theIOR,
239 SALOMEDS::SObject_ptr theFatherObject,
240 const int theTag = 0,
241 const char* thePixMap = 0,
242 const bool theSelectable = true)
244 SALOMEDS::SObject_var SO = SMESH_Gen_i::ObjectToSObject( theStudy, theIOR );
245 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
246 if ( SO->_is_nil() ) {
248 SO = aStudyBuilder->NewObject( theFatherObject );
249 else if ( !theFatherObject->FindSubObject( theTag, SO ))
250 SO = aStudyBuilder->NewObjectToTag( theFatherObject, theTag );
253 SALOMEDS::GenericAttribute_var anAttr;
254 if ( !CORBA::is_nil( theIOR )) {
255 anAttr = aStudyBuilder->FindOrCreateAttribute( SO, "AttributeIOR" );
256 SALOMEDS::AttributeIOR::_narrow(anAttr)->SetValue
257 ( SMESH_Gen_i::GetORB()->object_to_string( theIOR ) );
260 anAttr = aStudyBuilder->FindOrCreateAttribute( SO, "AttributePixMap" );
261 SALOMEDS::AttributePixMap::_narrow( anAttr )->SetPixMap( thePixMap );
263 if ( !theSelectable ) {
264 anAttr = aStudyBuilder->FindOrCreateAttribute( SO, "AttributeSelectable" );
265 SALOMEDS::AttributeSelectable::_narrow( anAttr )->SetSelectable( false );
270 //=======================================================================
273 //=======================================================================
275 void SMESH_Gen_i::SetName(SALOMEDS::SObject_ptr theSObject,
277 const char* theDefaultName)
279 if ( !theSObject->_is_nil() ) {
280 SALOMEDS::StudyBuilder_var aStudyBuilder = theSObject->GetStudy()->NewBuilder();
281 SALOMEDS::GenericAttribute_var anAttr =
282 aStudyBuilder->FindOrCreateAttribute( theSObject, "AttributeName" );
283 SALOMEDS::AttributeName_var aNameAttr = SALOMEDS::AttributeName::_narrow( anAttr );
284 if ( theName && strlen( theName ) != 0 )
285 aNameAttr->SetValue( theName );
287 CORBA::String_var curName = CORBA::string_dup( aNameAttr->Value() );
288 if ( strlen( curName ) == 0 ) {
289 TCollection_AsciiString aName( (char*) theDefaultName );
290 aName += TCollection_AsciiString("_") + TCollection_AsciiString( theSObject->Tag() );
291 aNameAttr->SetValue( aName.ToCString() );
297 //=======================================================================
298 //function : addReference
300 //=======================================================================
302 static void addReference (SALOMEDS::Study_ptr theStudy,
303 SALOMEDS::SObject_ptr theSObject,
304 CORBA::Object_ptr theToObject,
307 SALOMEDS::SObject_var aToObjSO = SMESH_Gen_i::ObjectToSObject( theStudy, theToObject );
308 if ( !aToObjSO->_is_nil() && !theSObject->_is_nil() ) {
309 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
310 SALOMEDS::SObject_var aReferenceSO;
312 // check if the reference to theToObject already exists
313 // and find a free label for the reference object
314 bool isReferred = false;
316 SALOMEDS::ChildIterator_var anIter = theStudy->NewChildIterator( theSObject );
317 for ( ; !isReferred && anIter->More(); anIter->Next(), ++tag ) {
318 if ( anIter->Value()->ReferencedObject( aReferenceSO )) {
319 if ( strcmp( aReferenceSO->GetID(), aToObjSO->GetID() ) == 0 )
322 else if ( !theTag ) {
323 SALOMEDS::GenericAttribute_var anAttr;
324 if ( !anIter->Value()->FindAttribute( anAttr, "AttributeIOR" ))
333 if ( !theSObject->FindSubObject( theTag, aReferenceSO ))
334 aReferenceSO = aStudyBuilder->NewObjectToTag( theSObject, theTag );
335 aStudyBuilder->Addreference( aReferenceSO, aToObjSO );
339 //=============================================================================
341 * SMESH_Gen_i::PublishInStudy
343 * Publish object in the study
345 //=============================================================================
347 SALOMEDS::SObject_ptr SMESH_Gen_i::PublishInStudy(SALOMEDS::Study_ptr theStudy,
348 SALOMEDS::SObject_ptr theSObject,
349 CORBA::Object_ptr theIOR,
351 throw (SALOME::SALOME_Exception)
353 Unexpect aCatch(SALOME_SalomeException);
354 SALOMEDS::SObject_var aSO;
355 if ( CORBA::is_nil( theStudy ) || CORBA::is_nil( theIOR ))
357 if(MYDEBUG) MESSAGE("PublishInStudy");
360 SMESH::SMESH_Mesh_var aMesh = SMESH::SMESH_Mesh::_narrow( theIOR );
361 if( !aMesh->_is_nil() )
362 aSO = PublishMesh( theStudy, aMesh, theName );
364 // Publishing a sub-mesh
365 SMESH::SMESH_subMesh_var aSubMesh = SMESH::SMESH_subMesh::_narrow( theIOR );
366 if( aSO->_is_nil() && !aSubMesh->_is_nil() ) {
367 GEOM::GEOM_Object_var aShapeObject = aSubMesh->GetSubShape();
368 aMesh = aSubMesh->GetFather();
369 aSO = PublishSubMesh( theStudy, aMesh, aSubMesh, aShapeObject, theName );
372 // Publishing a hypothesis or algorithm
373 SMESH::SMESH_Hypothesis_var aHyp = SMESH::SMESH_Hypothesis::_narrow( theIOR );
374 if ( aSO->_is_nil() && !aHyp->_is_nil() )
375 aSO = PublishHypothesis( theStudy, aHyp );
377 // Publishing a group
378 SMESH::SMESH_GroupBase_var aGroup = SMESH::SMESH_GroupBase::_narrow(theIOR);
379 if ( aSO->_is_nil() && !aGroup->_is_nil() ) {
380 GEOM::GEOM_Object_var aShapeObject;
381 aMesh = aGroup->GetMesh();
382 aSO = PublishGroup( theStudy, aMesh, aGroup, aShapeObject, theName );
384 if(MYDEBUG) MESSAGE("PublishInStudy_END");
389 //=======================================================================
390 //function : PublishComponent
392 //=======================================================================
394 SALOMEDS::SComponent_ptr SMESH_Gen_i::PublishComponent(SALOMEDS::Study_ptr theStudy)
396 if ( CORBA::is_nil( theStudy ))
397 return SALOMEDS::SComponent::_nil();
398 if(MYDEBUG) MESSAGE("PublishComponent");
400 SALOMEDS::SComponent_var father =
401 SALOMEDS::SComponent::_narrow( theStudy->FindComponent( ComponentDataType() ) );
402 if ( !CORBA::is_nil( father ) )
403 return father._retn();
405 SALOME_ModuleCatalog::ModuleCatalog_var aCat =
406 SALOME_ModuleCatalog::ModuleCatalog::_narrow( GetNS()->Resolve("/Kernel/ModulCatalog") );
407 if ( CORBA::is_nil( aCat ) )
408 return father._retn();
410 SALOME_ModuleCatalog::Acomponent_var aComp = aCat->GetComponent( ComponentDataType() );
411 if ( CORBA::is_nil( aComp ) )
412 return father._retn();
414 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
415 SALOMEDS::GenericAttribute_var anAttr;
416 SALOMEDS::AttributePixMap_var aPixmap;
418 father = aStudyBuilder->NewComponent( ComponentDataType() );
419 aStudyBuilder->DefineComponentInstance( father, SMESH_Gen::_this() );
420 anAttr = aStudyBuilder->FindOrCreateAttribute( father, "AttributePixMap" );
421 aPixmap = SALOMEDS::AttributePixMap::_narrow( anAttr );
422 aPixmap ->SetPixMap( "ICON_OBJBROWSER_SMESH" );
423 SetName( father, aComp->componentusername(), "MESH" );
424 if(MYDEBUG) MESSAGE("PublishComponent--END");
426 return father._retn();
429 //=============================================================================
431 * findMaxChildTag [ static internal ]
433 * Finds maximum child tag for the given object
435 //=============================================================================
437 static long findMaxChildTag( SALOMEDS::SObject_ptr theSObject )
440 if ( !theSObject->_is_nil() ) {
441 SALOMEDS::Study_var aStudy = theSObject->GetStudy();
442 if ( !aStudy->_is_nil() ) {
443 SALOMEDS::ChildIterator_var anIter = aStudy->NewChildIterator( theSObject );
444 for ( ; anIter->More(); anIter->Next() ) {
445 long nTag = anIter->Value()->Tag();
454 //=======================================================================
455 //function : PublishMesh
457 //=======================================================================
459 SALOMEDS::SObject_ptr SMESH_Gen_i::PublishMesh (SALOMEDS::Study_ptr theStudy,
460 SMESH::SMESH_Mesh_ptr theMesh,
463 if ( CORBA::is_nil( theStudy ) ||
464 CORBA::is_nil( theMesh ))
465 return SALOMEDS::SComponent::_nil();
466 if(MYDEBUG) MESSAGE("PublishMesh--IN");
468 // find or publish a mesh
470 SALOMEDS::SObject_var aMeshSO = ObjectToSObject( theStudy, theMesh );
471 if ( aMeshSO->_is_nil() )
473 SALOMEDS::SComponent_var father = PublishComponent( theStudy );
474 if ( father->_is_nil() )
475 return aMeshSO._retn();
477 // Find correct free tag
478 long aTag = findMaxChildTag( father.in() );
479 if ( aTag <= GetAlgorithmsRootTag() )
480 aTag = GetAlgorithmsRootTag() + 1;
484 aMeshSO = publish (theStudy, theMesh, father, aTag, "ICON_SMESH_TREE_MESH_WARN" );
485 if ( aMeshSO->_is_nil() )
486 return aMeshSO._retn();
488 SetName( aMeshSO, theName, "Mesh" );
490 // Add shape reference
492 GEOM::GEOM_Object_var aShapeObject = theMesh->GetShapeToMesh();
493 if ( !CORBA::is_nil( aShapeObject )) {
494 addReference( theStudy, aMeshSO, aShapeObject, GetRefOnShapeTag() );
496 // Publish global hypotheses
498 SMESH::ListOfHypothesis * hypList = theMesh->GetHypothesisList( aShapeObject );
500 for ( int i = 0; i < hypList->length(); i++ ) {
501 SMESH::SMESH_Hypothesis_var aHyp = SMESH::SMESH_Hypothesis::_narrow( (*hypList)[ i ]);
502 PublishHypothesis( theStudy, aHyp );
503 AddHypothesisToShape( theStudy, theMesh, aShapeObject, aHyp );
509 SMESH_Mesh_i* mesh_i = objectToServant<SMESH_Mesh_i>( theMesh );
511 return aMeshSO._retn();
512 map<int, SMESH_subMesh_i*>& subMap = mesh_i->_mapSubMesh_i;
513 map<int, SMESH_subMesh_i*>::iterator subIt = subMap.begin();
514 for ( ; subIt != subMap.end(); subIt++ ) {
515 SMESH::SMESH_subMesh_ptr aSubMesh = (*subIt).second->_this();
516 if ( !CORBA::is_nil( aSubMesh )) {
517 aShapeObject = aSubMesh->GetSubShape();
518 PublishSubMesh( theStudy, theMesh, aSubMesh, aShapeObject );
523 const map<int, SMESH::SMESH_GroupBase_ptr>& grMap = mesh_i->getGroups();
524 map<int, SMESH::SMESH_GroupBase_ptr>::const_iterator it = grMap.begin();
525 for ( ; it != grMap.end(); it++ )
527 SMESH::SMESH_GroupBase_ptr aGroup = (*it).second;
528 if ( !aGroup->_is_nil() ) {
529 GEOM::GEOM_Object_var aShapeObj;
530 SMESH::SMESH_GroupOnGeom_var aGeomGroup =
531 SMESH::SMESH_GroupOnGeom::_narrow( aGroup );
532 if ( !aGeomGroup->_is_nil() )
533 aShapeObj = aGeomGroup->GetShape();
534 PublishGroup( theStudy, theMesh, aGroup, aShapeObj );
538 if(MYDEBUG) MESSAGE("PublishMesh_END");
539 return aMeshSO._retn();
542 //=======================================================================
543 //function : PublishSubMesh
545 //=======================================================================
547 SALOMEDS::SObject_ptr SMESH_Gen_i::PublishSubMesh (SALOMEDS::Study_ptr theStudy,
548 SMESH::SMESH_Mesh_ptr theMesh,
549 SMESH::SMESH_subMesh_ptr theSubMesh,
550 GEOM::GEOM_Object_ptr theShapeObject,
553 if (theStudy->_is_nil() || theMesh->_is_nil() ||
554 theSubMesh->_is_nil() || theShapeObject->_is_nil() )
555 return SALOMEDS::SObject::_nil();
557 SALOMEDS::SObject_var aSubMeshSO = ObjectToSObject( theStudy, theSubMesh );
558 if ( aSubMeshSO->_is_nil() )
560 SALOMEDS::SObject_var aMeshSO = ObjectToSObject( theStudy, theMesh );
561 if ( aMeshSO->_is_nil() ) {
562 aMeshSO = PublishMesh( theStudy, theMesh );
563 if ( aMeshSO->_is_nil())
564 return SALOMEDS::SObject::_nil();
566 // Find submesh sub-tree tag
568 char* aRootName = "";
569 switch ( theShapeObject->GetShapeType() ) {
571 aRootTag = GetSubMeshOnVertexTag();
572 aRootName = "SubMeshes on Vertex";
575 aRootTag = GetSubMeshOnEdgeTag();
576 aRootName = "SubMeshes on Edge";
579 aRootTag = GetSubMeshOnWireTag();
580 aRootName = "SubMeshes on Wire";
583 aRootTag = GetSubMeshOnFaceTag();
584 aRootName = "SubMeshes on Face";
587 aRootTag = GetSubMeshOnShellTag();
588 aRootName = "SubMeshes on Shell";
591 aRootTag = GetSubMeshOnSolidTag();
592 aRootName = "SubMeshes on Solid";
595 aRootTag = GetSubMeshOnCompoundTag();
596 aRootName = "SubMeshes on Compound";
600 // Find or create submesh root
601 SALOMEDS::SObject_var aRootSO = publish (theStudy, CORBA::Object::_nil(),
602 aMeshSO, aRootTag, 0, false );
603 SetName( aRootSO, aRootName );
605 // Add new submesh to corresponding sub-tree
606 aSubMeshSO = publish (theStudy, theSubMesh, aRootSO, 0, "ICON_SMESH_TREE_MESH_WARN");
607 if ( aSubMeshSO->_is_nil() )
608 return aSubMeshSO._retn();
610 SetName( aSubMeshSO, theName, "SubMesh" );
612 // Add reference to theShapeObject
614 addReference( theStudy, aSubMeshSO, theShapeObject, 1 );
616 // Publish hypothesis
618 SMESH::ListOfHypothesis * hypList = theMesh->GetHypothesisList( theShapeObject );
620 for ( int i = 0; i < hypList->length(); i++ ) {
621 SMESH::SMESH_Hypothesis_var aHyp = SMESH::SMESH_Hypothesis::_narrow( (*hypList)[ i ]);
622 PublishHypothesis( theStudy, aHyp );
623 AddHypothesisToShape( theStudy, theMesh, theShapeObject, aHyp );
626 return aSubMeshSO._retn();
629 //=======================================================================
630 //function : PublishGroup
632 //=======================================================================
634 SALOMEDS::SObject_ptr SMESH_Gen_i::PublishGroup (SALOMEDS::Study_ptr theStudy,
635 SMESH::SMESH_Mesh_ptr theMesh,
636 SMESH::SMESH_GroupBase_ptr theGroup,
637 GEOM::GEOM_Object_ptr theShapeObject,
640 if (theStudy->_is_nil() || theMesh->_is_nil() || theGroup->_is_nil() )
641 return SALOMEDS::SObject::_nil();
643 SALOMEDS::SObject_var aGroupSO = ObjectToSObject( theStudy, theGroup );
644 if ( aGroupSO->_is_nil() )
646 SALOMEDS::SObject_var aMeshSO = ObjectToSObject( theStudy, theMesh );
647 if ( aMeshSO->_is_nil() ) {
648 aMeshSO = PublishInStudy( theStudy, SALOMEDS::SObject::_nil(), theMesh, "");
649 if ( aMeshSO->_is_nil())
650 return SALOMEDS::SObject::_nil();
652 int aType = (int)theGroup->GetType();
653 const char* aRootNames[] = {
654 "Compound Groups", "Groups of Nodes",
655 "Groups of Edges", "Groups of Faces", "Groups of Volumes" };
657 // Currently, groups with heterogenous content are not supported
658 if ( aType != SMESH::ALL ) {
659 long aRootTag = GetNodeGroupsTag() + aType - 1;
661 // Find or create groups root
662 SALOMEDS::SObject_var aRootSO = publish (theStudy, CORBA::Object::_nil(),
663 aMeshSO, aRootTag, 0, false );
665 SetName( aRootSO, aRootNames[aType] );
667 // Add new group to corresponding sub-tree
668 aGroupSO = publish (theStudy, theGroup, aRootSO, 0, "ICON_SMESH_TREE_GROUP" );
670 if ( aGroupSO->_is_nil() )
671 return aGroupSO._retn();
674 SetName( aGroupSO, theName, "Group" );
676 //Add reference to geometry
677 if ( !theShapeObject->_is_nil() )
678 addReference( theStudy, aGroupSO, theShapeObject, 1 );
680 return aGroupSO._retn();
683 //=======================================================================
684 //function : PublishHypothesis
686 //=======================================================================
688 SALOMEDS::SObject_ptr
689 SMESH_Gen_i::PublishHypothesis (SALOMEDS::Study_ptr theStudy,
690 SMESH::SMESH_Hypothesis_ptr theHyp,
693 if(MYDEBUG) MESSAGE("PublishHypothesis")
694 if (theStudy->_is_nil() || theHyp->_is_nil())
695 return SALOMEDS::SObject::_nil();
697 SALOMEDS::SObject_var aHypSO = ObjectToSObject( theStudy, theHyp );
698 if ( aHypSO->_is_nil() )
700 SALOMEDS::SComponent_var father = PublishComponent( theStudy );
701 if ( father->_is_nil() )
702 return aHypSO._retn();
704 //Find or Create Hypothesis root
705 bool isAlgo = ( !SMESH::SMESH_Algo::_narrow( theHyp )->_is_nil() );
706 int aRootTag = isAlgo ? GetAlgorithmsRootTag() : GetHypothesisRootTag();
707 SALOMEDS::SObject_var aRootSO =
708 publish (theStudy, CORBA::Object::_nil(),father, aRootTag,
709 isAlgo ? "ICON_SMESH_TREE_ALGO" : "ICON_SMESH_TREE_HYPO", false);
710 SetName( aRootSO, isAlgo ? "Algorithms" : "Hypotheses" );
712 // Add New Hypothesis
713 string aPmName = isAlgo ? "ICON_SMESH_TREE_ALGO_" : "ICON_SMESH_TREE_HYPO_";
714 aPmName += theHyp->GetName();
715 aHypSO = publish( theStudy, theHyp, aRootSO, 0, aPmName.c_str() );
718 if ( !aHypSO->_is_nil() ) {
719 CORBA::String_var aHypName = CORBA::string_dup( theHyp->GetName() );
720 SetName( aHypSO, theName, aHypName );
723 if(MYDEBUG) MESSAGE("PublishHypothesis--END")
724 return aHypSO._retn();
727 //=======================================================================
728 //function : GetMeshOrSubmeshByShape
730 //=======================================================================
732 SALOMEDS::SObject_ptr
733 SMESH_Gen_i::GetMeshOrSubmeshByShape (SALOMEDS::Study_ptr theStudy,
734 SMESH::SMESH_Mesh_ptr theMesh,
735 GEOM::GEOM_Object_ptr theShape)
737 if(MYDEBUG) MESSAGE("GetMeshOrSubmeshByShape")
738 SALOMEDS::SObject_var aMeshOrSubMesh;
739 if ( theShape->_is_nil() || theMesh->_is_nil() )
740 return aMeshOrSubMesh._retn();
742 TopoDS_Shape aShape = GeomObjectToShape( theShape );
743 SMESH_Mesh_i* mesh_i = objectToServant<SMESH_Mesh_i>( theMesh );
745 if ( !aShape.IsNull() && mesh_i && mesh_i->GetImpl().GetMeshDS() ) {
746 SMESHDS_Mesh* meshDS = mesh_i->GetImpl().GetMeshDS();
747 if ( aShape.IsSame( meshDS->ShapeToMesh() ))
748 aMeshOrSubMesh = ObjectToSObject( theStudy, theMesh );
750 int shapeID = meshDS->ShapeToIndex( aShape );
751 SMESH::SMESH_subMesh_var aSubMesh = mesh_i->getSubMesh(shapeID);
752 if ( !aSubMesh->_is_nil() )
753 aMeshOrSubMesh = ObjectToSObject( theStudy, aSubMesh );
756 if(MYDEBUG) MESSAGE("GetMeshOrSubmeshByShape--END")
757 return aMeshOrSubMesh._retn();
760 //=======================================================================
761 //function : AddHypothesisToShape
763 //=======================================================================
765 bool SMESH_Gen_i::AddHypothesisToShape(SALOMEDS::Study_ptr theStudy,
766 SMESH::SMESH_Mesh_ptr theMesh,
767 GEOM::GEOM_Object_ptr theShape,
768 SMESH::SMESH_Hypothesis_ptr theHyp)
770 if(MYDEBUG) MESSAGE("AddHypothesisToShape")
771 if (theStudy->_is_nil() || theMesh->_is_nil() ||
772 theHyp->_is_nil() || theShape->_is_nil() )
775 SALOMEDS::SObject_var aMeshSO = ObjectToSObject( theStudy, theMesh );
776 if ( aMeshSO->_is_nil() )
777 aMeshSO = PublishMesh( theStudy, theMesh );
778 SALOMEDS::SObject_var aHypSO = PublishHypothesis( theStudy, theHyp );
779 if ( aMeshSO->_is_nil() || aHypSO->_is_nil())
782 // Find a mesh or submesh refering to theShape
783 SALOMEDS::SObject_var aMeshOrSubMesh =
784 GetMeshOrSubmeshByShape( theStudy, theMesh, theShape );
785 if ( aMeshOrSubMesh->_is_nil() )
788 TopoDS_Shape aShape = GeomObjectToShape( theShape );
789 SMESH_Mesh_i* mesh_i = objectToServant<SMESH_Mesh_i>( theMesh );
790 if ( !aShape.IsNull() && mesh_i && mesh_i->GetImpl().GetMeshDS() ) {
791 SMESHDS_Mesh* meshDS = mesh_i->GetImpl().GetMeshDS();
792 int shapeID = meshDS->ShapeToIndex( aShape );
793 SMESH::SMESH_subMesh_var aSubMesh = mesh_i->getSubMesh(shapeID);
794 aMeshOrSubMesh = PublishSubMesh( theStudy, theMesh, aSubMesh, theShape );
796 if ( aMeshOrSubMesh->_is_nil() )
800 //Find or Create Applied Hypothesis root
801 bool aIsAlgo = !SMESH::SMESH_Algo::_narrow( theHyp )->_is_nil();
802 SALOMEDS::SObject_var AHR =
803 publish (theStudy, CORBA::Object::_nil(), aMeshOrSubMesh,
804 aIsAlgo ? GetRefOnAppliedAlgorithmsTag() : GetRefOnAppliedHypothesisTag(),
805 aIsAlgo ? "ICON_SMESH_TREE_ALGO" : "ICON_SMESH_TREE_HYPO", false);
806 SetName( AHR, aIsAlgo ? "Applied algorithms" : "Applied hypotheses" );
807 if ( AHR->_is_nil() )
810 addReference( theStudy, AHR, theHyp );
811 if(MYDEBUG) MESSAGE("AddHypothesisToShape--END")
815 //=======================================================================
816 //function : RemoveHypothesisFromShape
818 //=======================================================================
820 bool SMESH_Gen_i::RemoveHypothesisFromShape(SALOMEDS::Study_ptr theStudy,
821 SMESH::SMESH_Mesh_ptr theMesh,
822 GEOM::GEOM_Object_ptr theShape,
823 SMESH::SMESH_Hypothesis_ptr theHyp)
825 if (theStudy->_is_nil() || theMesh->_is_nil() ||
826 theHyp->_is_nil() || theShape->_is_nil() )
829 SALOMEDS::SObject_var aHypSO = ObjectToSObject( theStudy, theHyp );
830 if ( aHypSO->_is_nil() )
833 // Find a mesh or submesh refering to theShape
834 SALOMEDS::SObject_var aMeshOrSubMesh =
835 GetMeshOrSubmeshByShape( theStudy, theMesh, theShape );
836 if ( aMeshOrSubMesh->_is_nil() )
839 // Find and remove a reference to aHypSO
840 SALOMEDS::SObject_var aRef, anObj;
841 CORBA::String_var anID = CORBA::string_dup( aHypSO->GetID() );
842 SALOMEDS::ChildIterator_var it = theStudy->NewChildIterator( aMeshOrSubMesh );
843 for ( it->InitEx( true ); it->More(); it->Next() ) {
845 if (anObj->ReferencedObject( aRef ) && strcmp( aRef->GetID(), anID ) == 0 ) {
846 theStudy->NewBuilder()->RemoveObject( anObj );