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"
35 #include "SMESH_subMesh_i.hxx"
39 #include CORBA_CLIENT_HEADER(SALOME_ModuleCatalog)
41 #include "utilities.h"
42 #include "Utils_ExceptHandlers.hxx"
44 #include <TCollection_AsciiString.hxx>
47 static int MYDEBUG = 0;
49 static int MYDEBUG = 0;
52 //=============================================================================
54 * Get...Tag [ static ]
56 * Methods which determine SMESH data model structure
58 //=============================================================================
60 long SMESH_Gen_i::GetHypothesisRootTag()
62 return Tag_HypothesisRoot;
65 long SMESH_Gen_i::GetAlgorithmsRootTag()
67 return Tag_AlgorithmsRoot;
70 long SMESH_Gen_i::GetRefOnShapeTag()
72 return Tag_RefOnShape;
75 long SMESH_Gen_i::GetRefOnAppliedHypothesisTag()
77 return Tag_RefOnAppliedHypothesis;
80 long SMESH_Gen_i::GetRefOnAppliedAlgorithmsTag()
82 return Tag_RefOnAppliedAlgorithms;
85 long SMESH_Gen_i::GetSubMeshOnVertexTag()
87 return Tag_SubMeshOnVertex;
90 long SMESH_Gen_i::GetSubMeshOnEdgeTag()
92 return Tag_SubMeshOnEdge;
95 long SMESH_Gen_i::GetSubMeshOnFaceTag()
97 return Tag_SubMeshOnFace;
100 long SMESH_Gen_i::GetSubMeshOnSolidTag()
102 return Tag_SubMeshOnSolid;
105 long SMESH_Gen_i::GetSubMeshOnCompoundTag()
107 return Tag_SubMeshOnCompound;
110 long SMESH_Gen_i::GetSubMeshOnWireTag()
112 return Tag_SubMeshOnWire;
115 long SMESH_Gen_i::GetSubMeshOnShellTag()
117 return Tag_SubMeshOnShell;
120 long SMESH_Gen_i::GetNodeGroupsTag()
122 return Tag_NodeGroups;
125 long SMESH_Gen_i::GetEdgeGroupsTag()
127 return Tag_EdgeGroups;
130 long SMESH_Gen_i::GetFaceGroupsTag()
132 return Tag_FaceGroups;
135 long SMESH_Gen_i::GetVolumeGroupsTag()
137 return Tag_VolumeGroups;
140 //=============================================================================
142 * SMESH_Gen_i::CanPublishInStudy
144 * Returns true if object can be published in the study
146 //=============================================================================
148 bool SMESH_Gen_i::CanPublishInStudy(CORBA::Object_ptr theIOR)
150 if(MYDEBUG) MESSAGE("CanPublishInStudy - "<<!CORBA::is_nil(myCurrentStudy));
151 if(CORBA::is_nil(myCurrentStudy))
154 SMESH::SMESH_Mesh_var aMesh = SMESH::SMESH_Mesh::_narrow(theIOR);
155 if( !aMesh->_is_nil() )
158 SMESH::SMESH_subMesh_var aSubMesh = SMESH::SMESH_subMesh::_narrow(theIOR);
159 if( !aSubMesh->_is_nil() )
162 SMESH::SMESH_Hypothesis_var aHyp = SMESH::SMESH_Hypothesis::_narrow(theIOR);
163 if( !aHyp->_is_nil() )
166 SMESH::SMESH_GroupBase_var aGroup = SMESH::SMESH_GroupBase::_narrow(theIOR);
167 if( !aGroup->_is_nil() )
170 if(MYDEBUG) MESSAGE("CanPublishInStudy--CANT");
174 //=======================================================================
175 //function : ObjectToSObject
177 //=======================================================================
179 SALOMEDS::SObject_ptr SMESH_Gen_i::ObjectToSObject(SALOMEDS::Study_ptr theStudy,
180 CORBA::Object_ptr theObject)
182 SALOMEDS::SObject_var aSO;
183 if ( !CORBA::is_nil( theStudy ) && !CORBA::is_nil( theObject ))
185 CORBA::String_var objStr = SMESH_Gen_i::GetORB()->object_to_string( theObject );
186 aSO = theStudy->FindObjectIOR( objStr.in() );
191 //=======================================================================
192 //function : objectToServant
194 //=======================================================================
196 template<typename T> static inline T* objectToServant( CORBA::Object_ptr theIOR )
198 return dynamic_cast<T*>( SMESH_Gen_i::GetServant( theIOR ).in() );
201 //=======================================================================
202 //function : ShapeToGeomObject
204 //=======================================================================
206 GEOM::GEOM_Object_ptr SMESH_Gen_i::ShapeToGeomObject (const TopoDS_Shape& theShape )
208 GEOM::GEOM_Object_var aShapeObj;
209 if ( !theShape.IsNull() ) {
210 GEOM_Client* aClient = GetShapeReader();
211 TCollection_AsciiString IOR;
212 if ( aClient && aClient->Find( theShape, IOR ))
213 aShapeObj = GEOM::GEOM_Object::_narrow
214 ( GetORB()->string_to_object( IOR.ToCString() ) );
216 return aShapeObj._retn();
219 //=======================================================================
220 //function : GeomObjectToShape
222 //=======================================================================
224 TopoDS_Shape SMESH_Gen_i::GeomObjectToShape(GEOM::GEOM_Object_ptr theGeomObject)
227 if ( !theGeomObject->_is_nil() ) {
228 GEOM_Client* aClient = GetShapeReader();
229 GEOM::GEOM_Gen_ptr aGeomEngine = GetGeomEngine();
230 if ( aClient && !aGeomEngine->_is_nil () )
231 S = aClient->GetShape( aGeomEngine, theGeomObject );
236 //=======================================================================
239 //=======================================================================
241 static SALOMEDS::SObject_ptr publish(SALOMEDS::Study_ptr theStudy,
242 CORBA::Object_ptr theIOR,
243 SALOMEDS::SObject_ptr theFatherObject,
244 const int theTag = 0,
245 const char* thePixMap = 0,
246 const bool theSelectable = true)
248 SALOMEDS::SObject_var SO = SMESH_Gen_i::ObjectToSObject( theStudy, theIOR );
249 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
250 if ( SO->_is_nil() ) {
252 SO = aStudyBuilder->NewObject( theFatherObject );
253 else if ( !theFatherObject->FindSubObject( theTag, SO ))
254 SO = aStudyBuilder->NewObjectToTag( theFatherObject, theTag );
257 SALOMEDS::GenericAttribute_var anAttr;
258 if ( !CORBA::is_nil( theIOR )) {
259 anAttr = aStudyBuilder->FindOrCreateAttribute( SO, "AttributeIOR" );
260 CORBA::String_var objStr = SMESH_Gen_i::GetORB()->object_to_string( theIOR );
261 SALOMEDS::AttributeIOR::_narrow(anAttr)->SetValue( objStr.in() );
264 anAttr = aStudyBuilder->FindOrCreateAttribute( SO, "AttributePixMap" );
265 SALOMEDS::AttributePixMap::_narrow( anAttr )->SetPixMap( thePixMap );
267 if ( !theSelectable ) {
268 anAttr = aStudyBuilder->FindOrCreateAttribute( SO, "AttributeSelectable" );
269 SALOMEDS::AttributeSelectable::_narrow( anAttr )->SetSelectable( false );
274 //=======================================================================
277 //=======================================================================
279 void SMESH_Gen_i::SetName(SALOMEDS::SObject_ptr theSObject,
281 const char* theDefaultName)
283 if ( !theSObject->_is_nil() ) {
284 SALOMEDS::StudyBuilder_var aStudyBuilder = theSObject->GetStudy()->NewBuilder();
285 SALOMEDS::GenericAttribute_var anAttr =
286 aStudyBuilder->FindOrCreateAttribute( theSObject, "AttributeName" );
287 SALOMEDS::AttributeName_var aNameAttr = SALOMEDS::AttributeName::_narrow( anAttr );
288 if ( theName && strlen( theName ) != 0 )
289 aNameAttr->SetValue( theName );
291 CORBA::String_var curName = CORBA::string_dup( aNameAttr->Value() );
292 if ( strlen( curName ) == 0 ) {
293 TCollection_AsciiString aName( (char*) theDefaultName );
294 aName += TCollection_AsciiString("_") + TCollection_AsciiString( theSObject->Tag() );
295 aNameAttr->SetValue( aName.ToCString() );
301 //=======================================================================
302 //function : addReference
304 //=======================================================================
306 static void addReference (SALOMEDS::Study_ptr theStudy,
307 SALOMEDS::SObject_ptr theSObject,
308 CORBA::Object_ptr theToObject,
311 SALOMEDS::SObject_var aToObjSO = SMESH_Gen_i::ObjectToSObject( theStudy, theToObject );
312 if ( !aToObjSO->_is_nil() && !theSObject->_is_nil() ) {
313 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
314 SALOMEDS::SObject_var aReferenceSO;
316 // check if the reference to theToObject already exists
317 // and find a free label for the reference object
318 bool isReferred = false;
320 SALOMEDS::ChildIterator_var anIter = theStudy->NewChildIterator( theSObject );
321 for ( ; !isReferred && anIter->More(); anIter->Next(), ++tag ) {
322 if ( anIter->Value()->ReferencedObject( aReferenceSO )) {
323 if ( strcmp( aReferenceSO->GetID(), aToObjSO->GetID() ) == 0 )
326 else if ( !theTag ) {
327 SALOMEDS::GenericAttribute_var anAttr;
328 if ( !anIter->Value()->FindAttribute( anAttr, "AttributeIOR" ))
337 if ( !theSObject->FindSubObject( theTag, aReferenceSO ))
338 aReferenceSO = aStudyBuilder->NewObjectToTag( theSObject, theTag );
339 aStudyBuilder->Addreference( aReferenceSO, aToObjSO );
343 //=============================================================================
345 * SMESH_Gen_i::PublishInStudy
347 * Publish object in the study
349 //=============================================================================
351 SALOMEDS::SObject_ptr SMESH_Gen_i::PublishInStudy(SALOMEDS::Study_ptr theStudy,
352 SALOMEDS::SObject_ptr theSObject,
353 CORBA::Object_ptr theIOR,
355 throw (SALOME::SALOME_Exception)
357 Unexpect aCatch(SALOME_SalomeException);
358 SALOMEDS::SObject_var aSO;
359 if ( CORBA::is_nil( theStudy ) || CORBA::is_nil( theIOR ))
361 if(MYDEBUG) MESSAGE("PublishInStudy");
364 SMESH::SMESH_Mesh_var aMesh = SMESH::SMESH_Mesh::_narrow( theIOR );
365 if( !aMesh->_is_nil() )
366 aSO = PublishMesh( theStudy, aMesh, theName );
368 // Publishing a sub-mesh
369 SMESH::SMESH_subMesh_var aSubMesh = SMESH::SMESH_subMesh::_narrow( theIOR );
370 if( aSO->_is_nil() && !aSubMesh->_is_nil() ) {
371 GEOM::GEOM_Object_var aShapeObject = aSubMesh->GetSubShape();
372 aMesh = aSubMesh->GetFather();
373 aSO = PublishSubMesh( theStudy, aMesh, aSubMesh, aShapeObject, theName );
376 // Publishing a hypothesis or algorithm
377 SMESH::SMESH_Hypothesis_var aHyp = SMESH::SMESH_Hypothesis::_narrow( theIOR );
378 if ( aSO->_is_nil() && !aHyp->_is_nil() )
379 aSO = PublishHypothesis( theStudy, aHyp );
381 // Publishing a group
382 SMESH::SMESH_GroupBase_var aGroup = SMESH::SMESH_GroupBase::_narrow(theIOR);
383 if ( aSO->_is_nil() && !aGroup->_is_nil() ) {
384 GEOM::GEOM_Object_var aShapeObject;
385 aMesh = aGroup->GetMesh();
386 aSO = PublishGroup( theStudy, aMesh, aGroup, aShapeObject, theName );
388 if(MYDEBUG) MESSAGE("PublishInStudy_END");
393 //=======================================================================
394 //function : PublishComponent
396 //=======================================================================
398 SALOMEDS::SComponent_ptr SMESH_Gen_i::PublishComponent(SALOMEDS::Study_ptr theStudy)
400 if ( CORBA::is_nil( theStudy ))
401 return SALOMEDS::SComponent::_nil();
402 if(MYDEBUG) MESSAGE("PublishComponent");
404 SALOMEDS::SComponent_var father =
405 SALOMEDS::SComponent::_narrow( theStudy->FindComponent( ComponentDataType() ) );
406 if ( !CORBA::is_nil( father ) )
407 return father._retn();
409 SALOME_ModuleCatalog::ModuleCatalog_var aCat =
410 SALOME_ModuleCatalog::ModuleCatalog::_narrow( GetNS()->Resolve("/Kernel/ModulCatalog") );
411 if ( CORBA::is_nil( aCat ) )
412 return father._retn();
414 SALOME_ModuleCatalog::Acomponent_var aComp = aCat->GetComponent( ComponentDataType() );
415 if ( CORBA::is_nil( aComp ) )
416 return father._retn();
418 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
419 SALOMEDS::GenericAttribute_var anAttr;
420 SALOMEDS::AttributePixMap_var aPixmap;
422 father = aStudyBuilder->NewComponent( ComponentDataType() );
423 aStudyBuilder->DefineComponentInstance( father, SMESH_Gen::_this() );
424 anAttr = aStudyBuilder->FindOrCreateAttribute( father, "AttributePixMap" );
425 aPixmap = SALOMEDS::AttributePixMap::_narrow( anAttr );
426 aPixmap ->SetPixMap( "ICON_OBJBROWSER_SMESH" );
427 SetName( father, aComp->componentusername(), "MESH" );
428 if(MYDEBUG) MESSAGE("PublishComponent--END");
430 return father._retn();
433 //=============================================================================
435 * findMaxChildTag [ static internal ]
437 * Finds maximum child tag for the given object
439 //=============================================================================
441 static long findMaxChildTag( SALOMEDS::SObject_ptr theSObject )
444 if ( !theSObject->_is_nil() ) {
445 SALOMEDS::Study_var aStudy = theSObject->GetStudy();
446 if ( !aStudy->_is_nil() ) {
447 SALOMEDS::ChildIterator_var anIter = aStudy->NewChildIterator( theSObject );
448 for ( ; anIter->More(); anIter->Next() ) {
449 long nTag = anIter->Value()->Tag();
458 //=======================================================================
459 //function : PublishMesh
461 //=======================================================================
463 SALOMEDS::SObject_ptr SMESH_Gen_i::PublishMesh (SALOMEDS::Study_ptr theStudy,
464 SMESH::SMESH_Mesh_ptr theMesh,
467 if ( CORBA::is_nil( theStudy ) ||
468 CORBA::is_nil( theMesh ))
469 return SALOMEDS::SComponent::_nil();
470 if(MYDEBUG) MESSAGE("PublishMesh--IN");
472 // find or publish a mesh
474 SALOMEDS::SObject_var aMeshSO = ObjectToSObject( theStudy, theMesh );
475 if ( aMeshSO->_is_nil() )
477 SALOMEDS::SComponent_var father = PublishComponent( theStudy );
478 if ( father->_is_nil() )
479 return aMeshSO._retn();
481 // Find correct free tag
482 long aTag = findMaxChildTag( father.in() );
483 if ( aTag <= GetAlgorithmsRootTag() )
484 aTag = GetAlgorithmsRootTag() + 1;
488 aMeshSO = publish (theStudy, theMesh, father, aTag, "ICON_SMESH_TREE_MESH_WARN" );
489 if ( aMeshSO->_is_nil() )
490 return aMeshSO._retn();
492 SetName( aMeshSO, theName, "Mesh" );
494 // Add shape reference
496 GEOM::GEOM_Object_var aShapeObject = theMesh->GetShapeToMesh();
497 if ( !CORBA::is_nil( aShapeObject )) {
498 addReference( theStudy, aMeshSO, aShapeObject, GetRefOnShapeTag() );
500 // Publish global hypotheses
502 SMESH::ListOfHypothesis * hypList = theMesh->GetHypothesisList( aShapeObject );
504 for ( int i = 0; i < hypList->length(); i++ ) {
505 SMESH::SMESH_Hypothesis_var aHyp = SMESH::SMESH_Hypothesis::_narrow( (*hypList)[ i ]);
506 PublishHypothesis( theStudy, aHyp );
507 AddHypothesisToShape( theStudy, theMesh, aShapeObject, aHyp );
513 SMESH_Mesh_i* mesh_i = objectToServant<SMESH_Mesh_i>( theMesh );
515 return aMeshSO._retn();
516 map<int, SMESH_subMesh_i*>& subMap = mesh_i->_mapSubMesh_i;
517 map<int, SMESH_subMesh_i*>::iterator subIt = subMap.begin();
518 for ( ; subIt != subMap.end(); subIt++ ) {
519 SMESH::SMESH_subMesh_ptr aSubMesh = (*subIt).second->_this();
520 if ( !CORBA::is_nil( aSubMesh )) {
521 aShapeObject = aSubMesh->GetSubShape();
522 PublishSubMesh( theStudy, theMesh, aSubMesh, aShapeObject );
527 const map<int, SMESH::SMESH_GroupBase_ptr>& grMap = mesh_i->getGroups();
528 map<int, SMESH::SMESH_GroupBase_ptr>::const_iterator it = grMap.begin();
529 for ( ; it != grMap.end(); it++ )
531 SMESH::SMESH_GroupBase_ptr aGroup = (*it).second;
532 if ( !aGroup->_is_nil() ) {
533 GEOM::GEOM_Object_var aShapeObj;
534 SMESH::SMESH_GroupOnGeom_var aGeomGroup =
535 SMESH::SMESH_GroupOnGeom::_narrow( aGroup );
536 if ( !aGeomGroup->_is_nil() )
537 aShapeObj = aGeomGroup->GetShape();
538 PublishGroup( theStudy, theMesh, aGroup, aShapeObj );
542 if(MYDEBUG) MESSAGE("PublishMesh_END");
543 return aMeshSO._retn();
546 //=======================================================================
547 //function : PublishSubMesh
549 //=======================================================================
551 SALOMEDS::SObject_ptr SMESH_Gen_i::PublishSubMesh (SALOMEDS::Study_ptr theStudy,
552 SMESH::SMESH_Mesh_ptr theMesh,
553 SMESH::SMESH_subMesh_ptr theSubMesh,
554 GEOM::GEOM_Object_ptr theShapeObject,
557 if (theStudy->_is_nil() || theMesh->_is_nil() ||
558 theSubMesh->_is_nil() || theShapeObject->_is_nil() )
559 return SALOMEDS::SObject::_nil();
561 SALOMEDS::SObject_var aSubMeshSO = ObjectToSObject( theStudy, theSubMesh );
562 if ( aSubMeshSO->_is_nil() )
564 SALOMEDS::SObject_var aMeshSO = ObjectToSObject( theStudy, theMesh );
565 if ( aMeshSO->_is_nil() ) {
566 aMeshSO = PublishMesh( theStudy, theMesh );
567 if ( aMeshSO->_is_nil())
568 return SALOMEDS::SObject::_nil();
570 // Find submesh sub-tree tag
572 char* aRootName = "";
573 switch ( theShapeObject->GetShapeType() ) {
575 aRootTag = GetSubMeshOnVertexTag();
576 aRootName = "SubMeshes on Vertex";
579 aRootTag = GetSubMeshOnEdgeTag();
580 aRootName = "SubMeshes on Edge";
583 aRootTag = GetSubMeshOnWireTag();
584 aRootName = "SubMeshes on Wire";
587 aRootTag = GetSubMeshOnFaceTag();
588 aRootName = "SubMeshes on Face";
591 aRootTag = GetSubMeshOnShellTag();
592 aRootName = "SubMeshes on Shell";
595 aRootTag = GetSubMeshOnSolidTag();
596 aRootName = "SubMeshes on Solid";
599 aRootTag = GetSubMeshOnCompoundTag();
600 aRootName = "SubMeshes on Compound";
604 // Find or create submesh root
605 SALOMEDS::SObject_var aRootSO = publish (theStudy, CORBA::Object::_nil(),
606 aMeshSO, aRootTag, 0, false );
607 SetName( aRootSO, aRootName );
609 // Add new submesh to corresponding sub-tree
610 aSubMeshSO = publish (theStudy, theSubMesh, aRootSO, 0, "ICON_SMESH_TREE_MESH_WARN");
611 if ( aSubMeshSO->_is_nil() )
612 return aSubMeshSO._retn();
614 SetName( aSubMeshSO, theName, "SubMesh" );
616 // Add reference to theShapeObject
618 addReference( theStudy, aSubMeshSO, theShapeObject, 1 );
620 // Publish hypothesis
622 SMESH::ListOfHypothesis * hypList = theMesh->GetHypothesisList( theShapeObject );
624 for ( int i = 0; i < hypList->length(); i++ ) {
625 SMESH::SMESH_Hypothesis_var aHyp = SMESH::SMESH_Hypothesis::_narrow( (*hypList)[ i ]);
626 PublishHypothesis( theStudy, aHyp );
627 AddHypothesisToShape( theStudy, theMesh, theShapeObject, aHyp );
630 return aSubMeshSO._retn();
633 //=======================================================================
634 //function : PublishGroup
636 //=======================================================================
638 SALOMEDS::SObject_ptr SMESH_Gen_i::PublishGroup (SALOMEDS::Study_ptr theStudy,
639 SMESH::SMESH_Mesh_ptr theMesh,
640 SMESH::SMESH_GroupBase_ptr theGroup,
641 GEOM::GEOM_Object_ptr theShapeObject,
644 if (theStudy->_is_nil() || theMesh->_is_nil() || theGroup->_is_nil() )
645 return SALOMEDS::SObject::_nil();
647 SALOMEDS::SObject_var aGroupSO = ObjectToSObject( theStudy, theGroup );
648 if ( aGroupSO->_is_nil() )
650 SALOMEDS::SObject_var aMeshSO = ObjectToSObject( theStudy, theMesh );
651 if ( aMeshSO->_is_nil() ) {
652 aMeshSO = PublishInStudy( theStudy, SALOMEDS::SObject::_nil(), theMesh, "");
653 if ( aMeshSO->_is_nil())
654 return SALOMEDS::SObject::_nil();
656 int aType = (int)theGroup->GetType();
657 const char* aRootNames[] = {
658 "Compound Groups", "Groups of Nodes",
659 "Groups of Edges", "Groups of Faces", "Groups of Volumes" };
661 // Currently, groups with heterogenous content are not supported
662 if ( aType != SMESH::ALL ) {
663 long aRootTag = GetNodeGroupsTag() + aType - 1;
665 // Find or create groups root
666 SALOMEDS::SObject_var aRootSO = publish (theStudy, CORBA::Object::_nil(),
667 aMeshSO, aRootTag, 0, false );
669 SetName( aRootSO, aRootNames[aType] );
671 // Add new group to corresponding sub-tree
672 aGroupSO = publish (theStudy, theGroup, aRootSO, 0, "ICON_SMESH_TREE_GROUP" );
674 if ( aGroupSO->_is_nil() )
675 return aGroupSO._retn();
678 SetName( aGroupSO, theName, "Group" );
680 //Add reference to geometry
681 if ( !theShapeObject->_is_nil() )
682 addReference( theStudy, aGroupSO, theShapeObject, 1 );
684 return aGroupSO._retn();
687 //=======================================================================
688 //function : PublishHypothesis
690 //=======================================================================
692 SALOMEDS::SObject_ptr
693 SMESH_Gen_i::PublishHypothesis (SALOMEDS::Study_ptr theStudy,
694 SMESH::SMESH_Hypothesis_ptr theHyp,
697 if(MYDEBUG) MESSAGE("PublishHypothesis")
698 if (theStudy->_is_nil() || theHyp->_is_nil())
699 return SALOMEDS::SObject::_nil();
701 SALOMEDS::SObject_var aHypSO = ObjectToSObject( theStudy, theHyp );
702 if ( aHypSO->_is_nil() )
704 SALOMEDS::SComponent_var father = PublishComponent( theStudy );
705 if ( father->_is_nil() )
706 return aHypSO._retn();
708 //Find or Create Hypothesis root
709 bool isAlgo = ( !SMESH::SMESH_Algo::_narrow( theHyp )->_is_nil() );
710 int aRootTag = isAlgo ? GetAlgorithmsRootTag() : GetHypothesisRootTag();
711 SALOMEDS::SObject_var aRootSO =
712 publish (theStudy, CORBA::Object::_nil(),father, aRootTag,
713 isAlgo ? "ICON_SMESH_TREE_ALGO" : "ICON_SMESH_TREE_HYPO", false);
714 SetName( aRootSO, isAlgo ? "Algorithms" : "Hypotheses" );
716 // Add New Hypothesis
717 string aPmName = isAlgo ? "ICON_SMESH_TREE_ALGO_" : "ICON_SMESH_TREE_HYPO_";
718 aPmName += theHyp->GetName();
719 aHypSO = publish( theStudy, theHyp, aRootSO, 0, aPmName.c_str() );
722 if ( !aHypSO->_is_nil() ) {
723 CORBA::String_var aHypName = CORBA::string_dup( theHyp->GetName() );
724 SetName( aHypSO, theName, aHypName );
727 if(MYDEBUG) MESSAGE("PublishHypothesis--END")
728 return aHypSO._retn();
731 //=======================================================================
732 //function : GetMeshOrSubmeshByShape
734 //=======================================================================
736 SALOMEDS::SObject_ptr
737 SMESH_Gen_i::GetMeshOrSubmeshByShape (SALOMEDS::Study_ptr theStudy,
738 SMESH::SMESH_Mesh_ptr theMesh,
739 GEOM::GEOM_Object_ptr theShape)
741 if(MYDEBUG) MESSAGE("GetMeshOrSubmeshByShape")
742 SALOMEDS::SObject_var aMeshOrSubMesh;
743 if (theMesh->_is_nil() || ( theShape->_is_nil() && theMesh->HasShapeToMesh()))
744 return aMeshOrSubMesh._retn();
747 if(theMesh->HasShapeToMesh())
748 aShape = GeomObjectToShape( theShape );
750 aShape = SMESH_Mesh::PseudoShape();
752 SMESH_Mesh_i* mesh_i = objectToServant<SMESH_Mesh_i>( theMesh );
754 if ( !aShape.IsNull() && mesh_i && mesh_i->GetImpl().GetMeshDS() ) {
755 SMESHDS_Mesh* meshDS = mesh_i->GetImpl().GetMeshDS();
756 if ( aShape.IsSame( meshDS->ShapeToMesh() ))
757 aMeshOrSubMesh = ObjectToSObject( theStudy, theMesh );
759 int shapeID = meshDS->ShapeToIndex( aShape );
760 SMESH::SMESH_subMesh_var aSubMesh = mesh_i->getSubMesh(shapeID);
761 if ( !aSubMesh->_is_nil() )
762 aMeshOrSubMesh = ObjectToSObject( theStudy, aSubMesh );
765 if(MYDEBUG) MESSAGE("GetMeshOrSubmeshByShape--END")
766 return aMeshOrSubMesh._retn();
769 //=======================================================================
770 //function : AddHypothesisToShape
772 //=======================================================================
774 bool SMESH_Gen_i::AddHypothesisToShape(SALOMEDS::Study_ptr theStudy,
775 SMESH::SMESH_Mesh_ptr theMesh,
776 GEOM::GEOM_Object_ptr theShape,
777 SMESH::SMESH_Hypothesis_ptr theHyp)
779 if(MYDEBUG) MESSAGE("AddHypothesisToShape")
780 if (theStudy->_is_nil() || theMesh->_is_nil() ||
781 theHyp->_is_nil() || (theShape->_is_nil()
782 && theMesh->HasShapeToMesh()) )
785 SALOMEDS::SObject_var aMeshSO = ObjectToSObject( theStudy, theMesh );
786 if ( aMeshSO->_is_nil() )
787 aMeshSO = PublishMesh( theStudy, theMesh );
788 SALOMEDS::SObject_var aHypSO = PublishHypothesis( theStudy, theHyp );
789 if ( aMeshSO->_is_nil() || aHypSO->_is_nil())
792 // Find a mesh or submesh refering to theShape
793 SALOMEDS::SObject_var aMeshOrSubMesh =
794 GetMeshOrSubmeshByShape( theStudy, theMesh, theShape );
795 if ( aMeshOrSubMesh->_is_nil() )
798 TopoDS_Shape aShape = GeomObjectToShape( theShape );
799 SMESH_Mesh_i* mesh_i = objectToServant<SMESH_Mesh_i>( theMesh );
800 if ( !aShape.IsNull() && mesh_i && mesh_i->GetImpl().GetMeshDS() ) {
801 SMESHDS_Mesh* meshDS = mesh_i->GetImpl().GetMeshDS();
802 int shapeID = meshDS->ShapeToIndex( aShape );
803 SMESH::SMESH_subMesh_var aSubMesh = mesh_i->getSubMesh(shapeID);
804 aMeshOrSubMesh = PublishSubMesh( theStudy, theMesh, aSubMesh, theShape );
806 if ( aMeshOrSubMesh->_is_nil() )
810 //Find or Create Applied Hypothesis root
811 bool aIsAlgo = !SMESH::SMESH_Algo::_narrow( theHyp )->_is_nil();
812 SALOMEDS::SObject_var AHR =
813 publish (theStudy, CORBA::Object::_nil(), aMeshOrSubMesh,
814 aIsAlgo ? GetRefOnAppliedAlgorithmsTag() : GetRefOnAppliedHypothesisTag(),
815 aIsAlgo ? "ICON_SMESH_TREE_ALGO" : "ICON_SMESH_TREE_HYPO", false);
816 SetName( AHR, aIsAlgo ? "Applied algorithms" : "Applied hypotheses" );
817 if ( AHR->_is_nil() )
820 addReference( theStudy, AHR, theHyp );
821 if(MYDEBUG) MESSAGE("AddHypothesisToShape--END")
825 //=======================================================================
826 //function : RemoveHypothesisFromShape
828 //=======================================================================
830 bool SMESH_Gen_i::RemoveHypothesisFromShape(SALOMEDS::Study_ptr theStudy,
831 SMESH::SMESH_Mesh_ptr theMesh,
832 GEOM::GEOM_Object_ptr theShape,
833 SMESH::SMESH_Hypothesis_ptr theHyp)
835 if (theStudy->_is_nil() || theMesh->_is_nil() ||
836 theHyp->_is_nil() || (theShape->_is_nil()
837 && theMesh->HasShapeToMesh()))
840 SALOMEDS::SObject_var aHypSO = ObjectToSObject( theStudy, theHyp );
841 if ( aHypSO->_is_nil() )
844 // Find a mesh or submesh refering to theShape
845 SALOMEDS::SObject_var aMeshOrSubMesh =
846 GetMeshOrSubmeshByShape( theStudy, theMesh, theShape );
847 if ( aMeshOrSubMesh->_is_nil() )
850 // Find and remove a reference to aHypSO
851 SALOMEDS::SObject_var aRef, anObj;
852 CORBA::String_var anID = CORBA::string_dup( aHypSO->GetID() );
853 SALOMEDS::ChildIterator_var it = theStudy->NewChildIterator( aMeshOrSubMesh );
854 for ( it->InitEx( true ); it->More(); it->Next() ) {
856 if (anObj->ReferencedObject( aRef ) && strcmp( aRef->GetID(), anID ) == 0 ) {
857 theStudy->NewBuilder()->RemoveObject( anObj );