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 ))
184 CORBA::String_var objStr = SMESH_Gen_i::GetORB()->object_to_string( theObject );
185 aSO = theStudy->FindObjectIOR( objStr.in() );
190 //=======================================================================
191 //function : objectToServant
193 //=======================================================================
195 template<typename T> static inline T* objectToServant( CORBA::Object_ptr theIOR )
197 return dynamic_cast<T*>( SMESH_Gen_i::GetServant( theIOR ).in() );
200 //=======================================================================
201 //function : ShapeToGeomObject
203 //=======================================================================
205 GEOM::GEOM_Object_ptr SMESH_Gen_i::ShapeToGeomObject (const TopoDS_Shape& theShape )
207 GEOM::GEOM_Object_var aShapeObj;
208 if ( !theShape.IsNull() ) {
209 GEOM_Client* aClient = GetShapeReader();
210 TCollection_AsciiString IOR;
211 if ( aClient && aClient->Find( theShape, IOR ))
212 aShapeObj = GEOM::GEOM_Object::_narrow
213 ( GetORB()->string_to_object( IOR.ToCString() ) );
215 return aShapeObj._retn();
218 //=======================================================================
219 //function : GeomObjectToShape
221 //=======================================================================
223 TopoDS_Shape SMESH_Gen_i::GeomObjectToShape(GEOM::GEOM_Object_ptr theGeomObject)
226 if ( !theGeomObject->_is_nil() ) {
227 GEOM_Client* aClient = GetShapeReader();
228 GEOM::GEOM_Gen_var aGeomEngine = GetGeomEngine();
229 if ( aClient && !aGeomEngine->_is_nil () )
230 S = aClient->GetShape( aGeomEngine, theGeomObject );
235 //=======================================================================
238 //=======================================================================
240 static SALOMEDS::SObject_ptr publish(SALOMEDS::Study_ptr theStudy,
241 CORBA::Object_ptr theIOR,
242 SALOMEDS::SObject_ptr theFatherObject,
243 const int theTag = 0,
244 const char* thePixMap = 0,
245 const bool theSelectable = true)
247 SALOMEDS::SObject_var SO = SMESH_Gen_i::ObjectToSObject( theStudy, theIOR );
248 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
249 if ( SO->_is_nil() ) {
251 SO = aStudyBuilder->NewObject( theFatherObject );
252 else if ( !theFatherObject->FindSubObject( theTag, SO ))
253 SO = aStudyBuilder->NewObjectToTag( theFatherObject, theTag );
256 SALOMEDS::GenericAttribute_var anAttr;
257 if ( !CORBA::is_nil( theIOR )) {
258 anAttr = aStudyBuilder->FindOrCreateAttribute( SO, "AttributeIOR" );
259 CORBA::String_var objStr = SMESH_Gen_i::GetORB()->object_to_string( theIOR );
260 SALOMEDS::AttributeIOR::_narrow(anAttr)->SetValue( objStr.in() );
263 anAttr = aStudyBuilder->FindOrCreateAttribute( SO, "AttributePixMap" );
264 SALOMEDS::AttributePixMap::_narrow( anAttr )->SetPixMap( thePixMap );
266 if ( !theSelectable ) {
267 anAttr = aStudyBuilder->FindOrCreateAttribute( SO, "AttributeSelectable" );
268 SALOMEDS::AttributeSelectable::_narrow( anAttr )->SetSelectable( false );
273 //=======================================================================
276 //=======================================================================
278 void SMESH_Gen_i::SetName(SALOMEDS::SObject_ptr theSObject,
280 const char* theDefaultName)
282 if ( !theSObject->_is_nil() ) {
283 SALOMEDS::StudyBuilder_var aStudyBuilder = theSObject->GetStudy()->NewBuilder();
284 SALOMEDS::GenericAttribute_var anAttr =
285 aStudyBuilder->FindOrCreateAttribute( theSObject, "AttributeName" );
286 SALOMEDS::AttributeName_var aNameAttr = SALOMEDS::AttributeName::_narrow( anAttr );
287 if ( theName && strlen( theName ) != 0 )
288 aNameAttr->SetValue( theName );
290 CORBA::String_var curName = CORBA::string_dup( aNameAttr->Value() );
291 if ( strlen( curName ) == 0 ) {
292 TCollection_AsciiString aName( (char*) theDefaultName );
293 aName += TCollection_AsciiString("_") + TCollection_AsciiString( theSObject->Tag() );
294 aNameAttr->SetValue( aName.ToCString() );
300 //=======================================================================
301 //function : addReference
303 //=======================================================================
305 static void addReference (SALOMEDS::Study_ptr theStudy,
306 SALOMEDS::SObject_ptr theSObject,
307 CORBA::Object_ptr theToObject,
310 SALOMEDS::SObject_var aToObjSO = SMESH_Gen_i::ObjectToSObject( theStudy, theToObject );
311 if ( !aToObjSO->_is_nil() && !theSObject->_is_nil() ) {
312 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
313 SALOMEDS::SObject_var aReferenceSO;
315 // check if the reference to theToObject already exists
316 // and find a free label for the reference object
317 bool isReferred = false;
319 SALOMEDS::ChildIterator_var anIter = theStudy->NewChildIterator( theSObject );
320 for ( ; !isReferred && anIter->More(); anIter->Next(), ++tag ) {
321 if ( anIter->Value()->ReferencedObject( aReferenceSO )) {
322 if ( strcmp( aReferenceSO->GetID(), aToObjSO->GetID() ) == 0 )
325 else if ( !theTag ) {
326 SALOMEDS::GenericAttribute_var anAttr;
327 if ( !anIter->Value()->FindAttribute( anAttr, "AttributeIOR" ))
336 if ( !theSObject->FindSubObject( theTag, aReferenceSO ))
337 aReferenceSO = aStudyBuilder->NewObjectToTag( theSObject, theTag );
338 aStudyBuilder->Addreference( aReferenceSO, aToObjSO );
342 //=============================================================================
344 * SMESH_Gen_i::PublishInStudy
346 * Publish object in the study
348 //=============================================================================
350 SALOMEDS::SObject_ptr SMESH_Gen_i::PublishInStudy(SALOMEDS::Study_ptr theStudy,
351 SALOMEDS::SObject_ptr theSObject,
352 CORBA::Object_ptr theIOR,
354 throw (SALOME::SALOME_Exception)
356 Unexpect aCatch(SALOME_SalomeException);
357 SALOMEDS::SObject_var aSO;
358 if ( CORBA::is_nil( theStudy ) || CORBA::is_nil( theIOR ))
360 if(MYDEBUG) MESSAGE("PublishInStudy");
363 SMESH::SMESH_Mesh_var aMesh = SMESH::SMESH_Mesh::_narrow( theIOR );
364 if( !aMesh->_is_nil() )
365 aSO = PublishMesh( theStudy, aMesh, theName );
367 // Publishing a sub-mesh
368 SMESH::SMESH_subMesh_var aSubMesh = SMESH::SMESH_subMesh::_narrow( theIOR );
369 if( aSO->_is_nil() && !aSubMesh->_is_nil() ) {
370 GEOM::GEOM_Object_var aShapeObject = aSubMesh->GetSubShape();
371 aMesh = aSubMesh->GetFather();
372 aSO = PublishSubMesh( theStudy, aMesh, aSubMesh, aShapeObject, theName );
375 // Publishing a hypothesis or algorithm
376 SMESH::SMESH_Hypothesis_var aHyp = SMESH::SMESH_Hypothesis::_narrow( theIOR );
377 if ( aSO->_is_nil() && !aHyp->_is_nil() )
378 aSO = PublishHypothesis( theStudy, aHyp );
380 // Publishing a group
381 SMESH::SMESH_GroupBase_var aGroup = SMESH::SMESH_GroupBase::_narrow(theIOR);
382 if ( aSO->_is_nil() && !aGroup->_is_nil() ) {
383 GEOM::GEOM_Object_var aShapeObject;
384 aMesh = aGroup->GetMesh();
385 aSO = PublishGroup( theStudy, aMesh, aGroup, aShapeObject, theName );
387 if(MYDEBUG) MESSAGE("PublishInStudy_END");
392 //=======================================================================
393 //function : PublishComponent
395 //=======================================================================
397 SALOMEDS::SComponent_ptr SMESH_Gen_i::PublishComponent(SALOMEDS::Study_ptr theStudy)
399 if ( CORBA::is_nil( theStudy ))
400 return SALOMEDS::SComponent::_nil();
401 if(MYDEBUG) MESSAGE("PublishComponent");
403 SALOMEDS::SComponent_var father =
404 SALOMEDS::SComponent::_narrow( theStudy->FindComponent( ComponentDataType() ) );
405 if ( !CORBA::is_nil( father ) )
406 return father._retn();
408 SALOME_ModuleCatalog::ModuleCatalog_var aCat =
409 SALOME_ModuleCatalog::ModuleCatalog::_narrow( GetNS()->Resolve("/Kernel/ModulCatalog") );
410 if ( CORBA::is_nil( aCat ) )
411 return father._retn();
413 SALOME_ModuleCatalog::Acomponent_var aComp = aCat->GetComponent( ComponentDataType() );
414 if ( CORBA::is_nil( aComp ) )
415 return father._retn();
417 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
418 SALOMEDS::GenericAttribute_var anAttr;
419 SALOMEDS::AttributePixMap_var aPixmap;
421 father = aStudyBuilder->NewComponent( ComponentDataType() );
422 aStudyBuilder->DefineComponentInstance( father, SMESH_Gen::_this() );
423 anAttr = aStudyBuilder->FindOrCreateAttribute( father, "AttributePixMap" );
424 aPixmap = SALOMEDS::AttributePixMap::_narrow( anAttr );
425 aPixmap ->SetPixMap( "ICON_OBJBROWSER_SMESH" );
426 SetName( father, aComp->componentusername(), "MESH" );
427 if(MYDEBUG) MESSAGE("PublishComponent--END");
429 return father._retn();
432 //=============================================================================
434 * findMaxChildTag [ static internal ]
436 * Finds maximum child tag for the given object
438 //=============================================================================
440 static long findMaxChildTag( SALOMEDS::SObject_ptr theSObject )
443 if ( !theSObject->_is_nil() ) {
444 SALOMEDS::Study_var aStudy = theSObject->GetStudy();
445 if ( !aStudy->_is_nil() ) {
446 SALOMEDS::ChildIterator_var anIter = aStudy->NewChildIterator( theSObject );
447 for ( ; anIter->More(); anIter->Next() ) {
448 long nTag = anIter->Value()->Tag();
457 //=======================================================================
458 //function : PublishMesh
460 //=======================================================================
462 SALOMEDS::SObject_ptr SMESH_Gen_i::PublishMesh (SALOMEDS::Study_ptr theStudy,
463 SMESH::SMESH_Mesh_ptr theMesh,
466 if ( CORBA::is_nil( theStudy ) ||
467 CORBA::is_nil( theMesh ))
468 return SALOMEDS::SComponent::_nil();
469 if(MYDEBUG) MESSAGE("PublishMesh--IN");
471 // find or publish a mesh
473 SALOMEDS::SObject_var aMeshSO = ObjectToSObject( theStudy, theMesh );
474 if ( aMeshSO->_is_nil() )
476 SALOMEDS::SComponent_var father = PublishComponent( theStudy );
477 if ( father->_is_nil() )
478 return aMeshSO._retn();
480 // Find correct free tag
481 long aTag = findMaxChildTag( father.in() );
482 if ( aTag <= GetAlgorithmsRootTag() )
483 aTag = GetAlgorithmsRootTag() + 1;
487 aMeshSO = publish (theStudy, theMesh, father, aTag, "ICON_SMESH_TREE_MESH_WARN" );
488 if ( aMeshSO->_is_nil() )
489 return aMeshSO._retn();
491 SetName( aMeshSO, theName, "Mesh" );
493 // Add shape reference
495 GEOM::GEOM_Object_var aShapeObject = theMesh->GetShapeToMesh();
496 if ( !CORBA::is_nil( aShapeObject )) {
497 addReference( theStudy, aMeshSO, aShapeObject, GetRefOnShapeTag() );
499 // Publish global hypotheses
501 SMESH::ListOfHypothesis * hypList = theMesh->GetHypothesisList( aShapeObject );
503 for ( int i = 0; i < hypList->length(); i++ ) {
504 SMESH::SMESH_Hypothesis_var aHyp = SMESH::SMESH_Hypothesis::_narrow( (*hypList)[ i ]);
505 PublishHypothesis( theStudy, aHyp );
506 AddHypothesisToShape( theStudy, theMesh, aShapeObject, aHyp );
512 SMESH_Mesh_i* mesh_i = objectToServant<SMESH_Mesh_i>( theMesh );
514 return aMeshSO._retn();
515 map<int, SMESH_subMesh_i*>& subMap = mesh_i->_mapSubMesh_i;
516 map<int, SMESH_subMesh_i*>::iterator subIt = subMap.begin();
517 for ( ; subIt != subMap.end(); subIt++ ) {
518 SMESH::SMESH_subMesh_ptr aSubMesh = (*subIt).second->_this();
519 if ( !CORBA::is_nil( aSubMesh )) {
520 aShapeObject = aSubMesh->GetSubShape();
521 PublishSubMesh( theStudy, theMesh, aSubMesh, aShapeObject );
526 const map<int, SMESH::SMESH_GroupBase_ptr>& grMap = mesh_i->getGroups();
527 map<int, SMESH::SMESH_GroupBase_ptr>::const_iterator it = grMap.begin();
528 for ( ; it != grMap.end(); it++ )
530 SMESH::SMESH_GroupBase_ptr aGroup = (*it).second;
531 if ( !aGroup->_is_nil() ) {
532 GEOM::GEOM_Object_var aShapeObj;
533 SMESH::SMESH_GroupOnGeom_var aGeomGroup =
534 SMESH::SMESH_GroupOnGeom::_narrow( aGroup );
535 if ( !aGeomGroup->_is_nil() )
536 aShapeObj = aGeomGroup->GetShape();
537 PublishGroup( theStudy, theMesh, aGroup, aShapeObj );
541 if(MYDEBUG) MESSAGE("PublishMesh_END");
542 return aMeshSO._retn();
545 //=======================================================================
546 //function : PublishSubMesh
548 //=======================================================================
550 SALOMEDS::SObject_ptr SMESH_Gen_i::PublishSubMesh (SALOMEDS::Study_ptr theStudy,
551 SMESH::SMESH_Mesh_ptr theMesh,
552 SMESH::SMESH_subMesh_ptr theSubMesh,
553 GEOM::GEOM_Object_ptr theShapeObject,
556 if (theStudy->_is_nil() || theMesh->_is_nil() ||
557 theSubMesh->_is_nil() || theShapeObject->_is_nil() )
558 return SALOMEDS::SObject::_nil();
560 SALOMEDS::SObject_var aSubMeshSO = ObjectToSObject( theStudy, theSubMesh );
561 if ( aSubMeshSO->_is_nil() )
563 SALOMEDS::SObject_var aMeshSO = ObjectToSObject( theStudy, theMesh );
564 if ( aMeshSO->_is_nil() ) {
565 aMeshSO = PublishMesh( theStudy, theMesh );
566 if ( aMeshSO->_is_nil())
567 return SALOMEDS::SObject::_nil();
569 // Find submesh sub-tree tag
571 char* aRootName = "";
572 switch ( theShapeObject->GetShapeType() ) {
574 aRootTag = GetSubMeshOnVertexTag();
575 aRootName = "SubMeshes on Vertex";
578 aRootTag = GetSubMeshOnEdgeTag();
579 aRootName = "SubMeshes on Edge";
582 aRootTag = GetSubMeshOnWireTag();
583 aRootName = "SubMeshes on Wire";
586 aRootTag = GetSubMeshOnFaceTag();
587 aRootName = "SubMeshes on Face";
590 aRootTag = GetSubMeshOnShellTag();
591 aRootName = "SubMeshes on Shell";
594 aRootTag = GetSubMeshOnSolidTag();
595 aRootName = "SubMeshes on Solid";
598 aRootTag = GetSubMeshOnCompoundTag();
599 aRootName = "SubMeshes on Compound";
603 // Find or create submesh root
604 SALOMEDS::SObject_var aRootSO = publish (theStudy, CORBA::Object::_nil(),
605 aMeshSO, aRootTag, 0, false );
606 SetName( aRootSO, aRootName );
608 // Add new submesh to corresponding sub-tree
609 aSubMeshSO = publish (theStudy, theSubMesh, aRootSO, 0, "ICON_SMESH_TREE_MESH_WARN");
610 if ( aSubMeshSO->_is_nil() )
611 return aSubMeshSO._retn();
613 SetName( aSubMeshSO, theName, "SubMesh" );
615 // Add reference to theShapeObject
617 addReference( theStudy, aSubMeshSO, theShapeObject, 1 );
619 // Publish hypothesis
621 SMESH::ListOfHypothesis * hypList = theMesh->GetHypothesisList( theShapeObject );
623 for ( int i = 0; i < hypList->length(); i++ ) {
624 SMESH::SMESH_Hypothesis_var aHyp = SMESH::SMESH_Hypothesis::_narrow( (*hypList)[ i ]);
625 PublishHypothesis( theStudy, aHyp );
626 AddHypothesisToShape( theStudy, theMesh, theShapeObject, aHyp );
629 return aSubMeshSO._retn();
632 //=======================================================================
633 //function : PublishGroup
635 //=======================================================================
637 SALOMEDS::SObject_ptr SMESH_Gen_i::PublishGroup (SALOMEDS::Study_ptr theStudy,
638 SMESH::SMESH_Mesh_ptr theMesh,
639 SMESH::SMESH_GroupBase_ptr theGroup,
640 GEOM::GEOM_Object_ptr theShapeObject,
643 if (theStudy->_is_nil() || theMesh->_is_nil() || theGroup->_is_nil() )
644 return SALOMEDS::SObject::_nil();
646 SALOMEDS::SObject_var aGroupSO = ObjectToSObject( theStudy, theGroup );
647 if ( aGroupSO->_is_nil() )
649 SALOMEDS::SObject_var aMeshSO = ObjectToSObject( theStudy, theMesh );
650 if ( aMeshSO->_is_nil() ) {
651 aMeshSO = PublishInStudy( theStudy, SALOMEDS::SObject::_nil(), theMesh, "");
652 if ( aMeshSO->_is_nil())
653 return SALOMEDS::SObject::_nil();
655 int aType = (int)theGroup->GetType();
656 const char* aRootNames[] = {
657 "Compound Groups", "Groups of Nodes",
658 "Groups of Edges", "Groups of Faces", "Groups of Volumes" };
660 // Currently, groups with heterogenous content are not supported
661 if ( aType != SMESH::ALL ) {
662 long aRootTag = GetNodeGroupsTag() + aType - 1;
664 // Find or create groups root
665 SALOMEDS::SObject_var aRootSO = publish (theStudy, CORBA::Object::_nil(),
666 aMeshSO, aRootTag, 0, false );
668 SetName( aRootSO, aRootNames[aType] );
670 // Add new group to corresponding sub-tree
671 aGroupSO = publish (theStudy, theGroup, aRootSO, 0, "ICON_SMESH_TREE_GROUP" );
673 if ( aGroupSO->_is_nil() )
674 return aGroupSO._retn();
677 SetName( aGroupSO, theName, "Group" );
679 //Add reference to geometry
680 if ( !theShapeObject->_is_nil() )
681 addReference( theStudy, aGroupSO, theShapeObject, 1 );
683 return aGroupSO._retn();
686 //=======================================================================
687 //function : PublishHypothesis
689 //=======================================================================
691 SALOMEDS::SObject_ptr
692 SMESH_Gen_i::PublishHypothesis (SALOMEDS::Study_ptr theStudy,
693 SMESH::SMESH_Hypothesis_ptr theHyp,
696 if(MYDEBUG) MESSAGE("PublishHypothesis")
697 if (theStudy->_is_nil() || theHyp->_is_nil())
698 return SALOMEDS::SObject::_nil();
700 SALOMEDS::SObject_var aHypSO = ObjectToSObject( theStudy, theHyp );
701 if ( aHypSO->_is_nil() )
703 SALOMEDS::SComponent_var father = PublishComponent( theStudy );
704 if ( father->_is_nil() )
705 return aHypSO._retn();
707 //Find or Create Hypothesis root
708 bool isAlgo = ( !SMESH::SMESH_Algo::_narrow( theHyp )->_is_nil() );
709 int aRootTag = isAlgo ? GetAlgorithmsRootTag() : GetHypothesisRootTag();
710 SALOMEDS::SObject_var aRootSO =
711 publish (theStudy, CORBA::Object::_nil(),father, aRootTag,
712 isAlgo ? "ICON_SMESH_TREE_ALGO" : "ICON_SMESH_TREE_HYPO", false);
713 SetName( aRootSO, isAlgo ? "Algorithms" : "Hypotheses" );
715 // Add New Hypothesis
716 string aPmName = isAlgo ? "ICON_SMESH_TREE_ALGO_" : "ICON_SMESH_TREE_HYPO_";
717 aPmName += theHyp->GetName();
718 aHypSO = publish( theStudy, theHyp, aRootSO, 0, aPmName.c_str() );
721 if ( !aHypSO->_is_nil() ) {
722 CORBA::String_var aHypName = CORBA::string_dup( theHyp->GetName() );
723 SetName( aHypSO, theName, aHypName );
726 if(MYDEBUG) MESSAGE("PublishHypothesis--END")
727 return aHypSO._retn();
730 //=======================================================================
731 //function : GetMeshOrSubmeshByShape
733 //=======================================================================
735 SALOMEDS::SObject_ptr
736 SMESH_Gen_i::GetMeshOrSubmeshByShape (SALOMEDS::Study_ptr theStudy,
737 SMESH::SMESH_Mesh_ptr theMesh,
738 GEOM::GEOM_Object_ptr theShape)
740 if(MYDEBUG) MESSAGE("GetMeshOrSubmeshByShape")
741 SALOMEDS::SObject_var aMeshOrSubMesh;
742 if ( theShape->_is_nil() || theMesh->_is_nil() )
743 return aMeshOrSubMesh._retn();
745 TopoDS_Shape aShape = GeomObjectToShape( theShape );
746 SMESH_Mesh_i* mesh_i = objectToServant<SMESH_Mesh_i>( theMesh );
748 if ( !aShape.IsNull() && mesh_i && mesh_i->GetImpl().GetMeshDS() ) {
749 SMESHDS_Mesh* meshDS = mesh_i->GetImpl().GetMeshDS();
750 if ( aShape.IsSame( meshDS->ShapeToMesh() ))
751 aMeshOrSubMesh = ObjectToSObject( theStudy, theMesh );
753 int shapeID = meshDS->ShapeToIndex( aShape );
754 SMESH::SMESH_subMesh_var aSubMesh = mesh_i->getSubMesh(shapeID);
755 if ( !aSubMesh->_is_nil() )
756 aMeshOrSubMesh = ObjectToSObject( theStudy, aSubMesh );
759 if(MYDEBUG) MESSAGE("GetMeshOrSubmeshByShape--END")
760 return aMeshOrSubMesh._retn();
763 //=======================================================================
764 //function : AddHypothesisToShape
766 //=======================================================================
768 bool SMESH_Gen_i::AddHypothesisToShape(SALOMEDS::Study_ptr theStudy,
769 SMESH::SMESH_Mesh_ptr theMesh,
770 GEOM::GEOM_Object_ptr theShape,
771 SMESH::SMESH_Hypothesis_ptr theHyp)
773 if(MYDEBUG) MESSAGE("AddHypothesisToShape")
774 if (theStudy->_is_nil() || theMesh->_is_nil() ||
775 theHyp->_is_nil() || theShape->_is_nil() )
778 SALOMEDS::SObject_var aMeshSO = ObjectToSObject( theStudy, theMesh );
779 if ( aMeshSO->_is_nil() )
780 aMeshSO = PublishMesh( theStudy, theMesh );
781 SALOMEDS::SObject_var aHypSO = PublishHypothesis( theStudy, theHyp );
782 if ( aMeshSO->_is_nil() || aHypSO->_is_nil())
785 // Find a mesh or submesh refering to theShape
786 SALOMEDS::SObject_var aMeshOrSubMesh =
787 GetMeshOrSubmeshByShape( theStudy, theMesh, theShape );
788 if ( aMeshOrSubMesh->_is_nil() )
791 TopoDS_Shape aShape = GeomObjectToShape( theShape );
792 SMESH_Mesh_i* mesh_i = objectToServant<SMESH_Mesh_i>( theMesh );
793 if ( !aShape.IsNull() && mesh_i && mesh_i->GetImpl().GetMeshDS() ) {
794 SMESHDS_Mesh* meshDS = mesh_i->GetImpl().GetMeshDS();
795 int shapeID = meshDS->ShapeToIndex( aShape );
796 SMESH::SMESH_subMesh_var aSubMesh = mesh_i->getSubMesh(shapeID);
797 aMeshOrSubMesh = PublishSubMesh( theStudy, theMesh, aSubMesh, theShape );
799 if ( aMeshOrSubMesh->_is_nil() )
803 //Find or Create Applied Hypothesis root
804 bool aIsAlgo = !SMESH::SMESH_Algo::_narrow( theHyp )->_is_nil();
805 SALOMEDS::SObject_var AHR =
806 publish (theStudy, CORBA::Object::_nil(), aMeshOrSubMesh,
807 aIsAlgo ? GetRefOnAppliedAlgorithmsTag() : GetRefOnAppliedHypothesisTag(),
808 aIsAlgo ? "ICON_SMESH_TREE_ALGO" : "ICON_SMESH_TREE_HYPO", false);
809 SetName( AHR, aIsAlgo ? "Applied algorithms" : "Applied hypotheses" );
810 if ( AHR->_is_nil() )
813 addReference( theStudy, AHR, theHyp );
814 if(MYDEBUG) MESSAGE("AddHypothesisToShape--END")
818 //=======================================================================
819 //function : RemoveHypothesisFromShape
821 //=======================================================================
823 bool SMESH_Gen_i::RemoveHypothesisFromShape(SALOMEDS::Study_ptr theStudy,
824 SMESH::SMESH_Mesh_ptr theMesh,
825 GEOM::GEOM_Object_ptr theShape,
826 SMESH::SMESH_Hypothesis_ptr theHyp)
828 if (theStudy->_is_nil() || theMesh->_is_nil() ||
829 theHyp->_is_nil() || theShape->_is_nil() )
832 SALOMEDS::SObject_var aHypSO = ObjectToSObject( theStudy, theHyp );
833 if ( aHypSO->_is_nil() )
836 // Find a mesh or submesh refering to theShape
837 SALOMEDS::SObject_var aMeshOrSubMesh =
838 GetMeshOrSubmeshByShape( theStudy, theMesh, theShape );
839 if ( aMeshOrSubMesh->_is_nil() )
842 // Find and remove a reference to aHypSO
843 SALOMEDS::SObject_var aRef, anObj;
844 CORBA::String_var anID = CORBA::string_dup( aHypSO->GetID() );
845 SALOMEDS::ChildIterator_var it = theStudy->NewChildIterator( aMeshOrSubMesh );
846 for ( it->InitEx( true ); it->More(); it->Next() ) {
848 if (anObj->ReferencedObject( aRef ) && strcmp( aRef->GetID(), anID ) == 0 ) {
849 theStudy->NewBuilder()->RemoveObject( anObj );