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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
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 bool isReferred = false;
313 SALOMEDS::ChildIterator_var anIter = theStudy->NewChildIterator( theSObject );
314 for ( ; !isReferred && anIter->More(); anIter->Next() ) {
315 if ( anIter->Value()->ReferencedObject( aReferenceSO ) &&
316 strcmp( aReferenceSO->GetID(), aToObjSO->GetID() ) == 0 )
320 aReferenceSO = aStudyBuilder->NewObject( theSObject );
321 aStudyBuilder->Addreference( aReferenceSO, aToObjSO );
325 if ( !theSObject->FindSubObject( theTag, aReferenceSO ))
326 aReferenceSO = aStudyBuilder->NewObjectToTag( theSObject, theTag );
327 aStudyBuilder->Addreference( aReferenceSO, aToObjSO );
332 //=============================================================================
334 * SMESH_Gen_i::PublishInStudy
336 * Publish object in the study
338 //=============================================================================
340 SALOMEDS::SObject_ptr SMESH_Gen_i::PublishInStudy(SALOMEDS::Study_ptr theStudy,
341 SALOMEDS::SObject_ptr theSObject,
342 CORBA::Object_ptr theIOR,
344 throw (SALOME::SALOME_Exception)
346 Unexpect aCatch(SALOME_SalomeException);
347 SALOMEDS::SObject_var aSO;
348 if ( CORBA::is_nil( theStudy ) || CORBA::is_nil( theIOR ))
350 if(MYDEBUG) MESSAGE("PublishInStudy");
353 SMESH::SMESH_Mesh_var aMesh = SMESH::SMESH_Mesh::_narrow( theIOR );
354 if( !aMesh->_is_nil() )
355 aSO = PublishMesh( theStudy, aMesh, theName );
357 // Publishing a sub-mesh
358 SMESH::SMESH_subMesh_var aSubMesh = SMESH::SMESH_subMesh::_narrow( theIOR );
359 if( aSO->_is_nil() && !aSubMesh->_is_nil() ) {
360 GEOM::GEOM_Object_var aShapeObject = aSubMesh->GetSubShape();
361 aMesh = aSubMesh->GetFather();
362 aSO = PublishSubMesh( theStudy, aMesh, aSubMesh, aShapeObject, theName );
365 // Publishing a hypothesis or algorithm
366 SMESH::SMESH_Hypothesis_var aHyp = SMESH::SMESH_Hypothesis::_narrow( theIOR );
367 if ( aSO->_is_nil() && !aHyp->_is_nil() )
368 aSO = PublishHypothesis( theStudy, aHyp );
370 // Publishing a group
371 SMESH::SMESH_GroupBase_var aGroup = SMESH::SMESH_GroupBase::_narrow(theIOR);
372 if ( aSO->_is_nil() && !aGroup->_is_nil() ) {
373 GEOM::GEOM_Object_var aShapeObject;
374 aMesh = aGroup->GetMesh();
375 aSO = PublishGroup( theStudy, aMesh, aGroup, aShapeObject, theName );
377 if(MYDEBUG) MESSAGE("PublishInStudy_END");
382 //=======================================================================
383 //function : PublishComponent
385 //=======================================================================
387 SALOMEDS::SComponent_ptr SMESH_Gen_i::PublishComponent(SALOMEDS::Study_ptr theStudy)
389 if ( CORBA::is_nil( theStudy ))
390 return SALOMEDS::SComponent::_nil();
391 if(MYDEBUG) MESSAGE("PublishComponent");
393 SALOMEDS::SComponent_var father =
394 SALOMEDS::SComponent::_narrow( theStudy->FindComponent( ComponentDataType() ) );
395 if ( !CORBA::is_nil( father ) )
396 return father._retn();
398 SALOME_ModuleCatalog::ModuleCatalog_var aCat =
399 SALOME_ModuleCatalog::ModuleCatalog::_narrow( GetNS()->Resolve("/Kernel/ModulCatalog") );
400 if ( CORBA::is_nil( aCat ) )
401 return father._retn();
403 SALOME_ModuleCatalog::Acomponent_var aComp = aCat->GetComponent( ComponentDataType() );
404 if ( CORBA::is_nil( aComp ) )
405 return father._retn();
407 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
408 SALOMEDS::GenericAttribute_var anAttr;
409 SALOMEDS::AttributePixMap_var aPixmap;
411 father = aStudyBuilder->NewComponent( ComponentDataType() );
412 aStudyBuilder->DefineComponentInstance( father, SMESH_Gen::_this() );
413 anAttr = aStudyBuilder->FindOrCreateAttribute( father, "AttributePixMap" );
414 aPixmap = SALOMEDS::AttributePixMap::_narrow( anAttr );
415 aPixmap ->SetPixMap( "ICON_OBJBROWSER_SMESH" );
416 SetName( father, aComp->componentusername(), "MESH" );
417 if(MYDEBUG) MESSAGE("PublishComponent--END");
419 return father._retn();
422 //=============================================================================
424 * findMaxChildTag [ static internal ]
426 * Finds maximum child tag for the given object
428 //=============================================================================
430 static long findMaxChildTag( SALOMEDS::SObject_ptr theSObject )
433 if ( !theSObject->_is_nil() ) {
434 SALOMEDS::Study_var aStudy = theSObject->GetStudy();
435 if ( !aStudy->_is_nil() ) {
436 SALOMEDS::ChildIterator_var anIter = aStudy->NewChildIterator( theSObject );
437 for ( ; anIter->More(); anIter->Next() ) {
438 long nTag = anIter->Value()->Tag();
447 //=======================================================================
448 //function : PublishMesh
450 //=======================================================================
452 SALOMEDS::SObject_ptr SMESH_Gen_i::PublishMesh (SALOMEDS::Study_ptr theStudy,
453 SMESH::SMESH_Mesh_ptr theMesh,
456 if ( CORBA::is_nil( theStudy ) ||
457 CORBA::is_nil( theMesh ))
458 return SALOMEDS::SComponent::_nil();
459 if(MYDEBUG) MESSAGE("PublishMesh--IN");
461 // find or publish a mesh
463 SALOMEDS::SObject_var aMeshSO = ObjectToSObject( theStudy, theMesh );
464 if ( aMeshSO->_is_nil() )
466 SALOMEDS::SComponent_var father = PublishComponent( theStudy );
467 if ( father->_is_nil() )
468 return aMeshSO._retn();
470 // Find correct free tag
471 long aTag = findMaxChildTag( father.in() );
472 if ( aTag <= GetAlgorithmsRootTag() )
473 aTag = GetAlgorithmsRootTag() + 1;
477 aMeshSO = publish (theStudy, theMesh, father, aTag, "ICON_SMESH_TREE_MESH_WARN" );
478 if ( aMeshSO->_is_nil() )
479 return aMeshSO._retn();
481 SetName( aMeshSO, theName, "Mesh" );
483 // Add shape reference
485 GEOM::GEOM_Object_var aShapeObject = theMesh->GetShapeToMesh();
486 if ( !CORBA::is_nil( aShapeObject )) {
487 addReference( theStudy, aMeshSO, aShapeObject, GetRefOnShapeTag() );
489 // Publish global hypotheses
491 SMESH::ListOfHypothesis * hypList = theMesh->GetHypothesisList( aShapeObject );
493 for ( int i = 0; i < hypList->length(); i++ ) {
494 SMESH::SMESH_Hypothesis_var aHyp = SMESH::SMESH_Hypothesis::_narrow( (*hypList)[ i ]);
495 PublishHypothesis( theStudy, aHyp );
496 AddHypothesisToShape( theStudy, theMesh, aShapeObject, aHyp );
502 SMESH_Mesh_i* mesh_i = objectToServant<SMESH_Mesh_i>( theMesh );
504 return aMeshSO._retn();
505 map<int, SMESH_subMesh_i*>& subMap = mesh_i->_mapSubMesh_i;
506 map<int, SMESH_subMesh_i*>::iterator subIt = subMap.begin();
507 for ( ; subIt != subMap.end(); subIt++ ) {
508 SMESH::SMESH_subMesh_ptr aSubMesh = (*subIt).second->_this();
509 if ( !CORBA::is_nil( aSubMesh )) {
510 aShapeObject = aSubMesh->GetSubShape();
511 PublishSubMesh( theStudy, theMesh, aSubMesh, aShapeObject );
516 const map<int, SMESH::SMESH_GroupBase_ptr>& grMap = mesh_i->getGroups();
517 map<int, SMESH::SMESH_GroupBase_ptr>::const_iterator it = grMap.begin();
518 for ( ; it != grMap.end(); it++ )
520 SMESH::SMESH_GroupBase_ptr aGroup = (*it).second;
521 if ( !aGroup->_is_nil() ) {
522 GEOM::GEOM_Object_var aShapeObj;
523 SMESH::SMESH_GroupOnGeom_var aGeomGroup =
524 SMESH::SMESH_GroupOnGeom::_narrow( aGroup );
525 if ( !aGeomGroup->_is_nil() )
526 aShapeObj = aGeomGroup->GetShape();
527 PublishGroup( theStudy, theMesh, aGroup, aShapeObj );
531 if(MYDEBUG) MESSAGE("PublishMesh_END");
532 return aMeshSO._retn();
535 //=======================================================================
536 //function : PublishSubMesh
538 //=======================================================================
540 SALOMEDS::SObject_ptr SMESH_Gen_i::PublishSubMesh (SALOMEDS::Study_ptr theStudy,
541 SMESH::SMESH_Mesh_ptr theMesh,
542 SMESH::SMESH_subMesh_ptr theSubMesh,
543 GEOM::GEOM_Object_ptr theShapeObject,
546 if (theStudy->_is_nil() || theMesh->_is_nil() ||
547 theSubMesh->_is_nil() || theShapeObject->_is_nil() )
548 return SALOMEDS::SObject::_nil();
550 SALOMEDS::SObject_var aSubMeshSO = ObjectToSObject( theStudy, theSubMesh );
551 if ( aSubMeshSO->_is_nil() )
553 SALOMEDS::SObject_var aMeshSO = ObjectToSObject( theStudy, theMesh );
554 if ( aMeshSO->_is_nil() ) {
555 aMeshSO = PublishMesh( theStudy, theMesh );
556 if ( aMeshSO->_is_nil())
557 return SALOMEDS::SObject::_nil();
559 // Find submesh sub-tree tag
561 char* aRootName = "";
562 switch ( theShapeObject->GetShapeType() ) {
564 aRootTag = GetSubMeshOnVertexTag();
565 aRootName = "SubMeshes on Vertex";
568 aRootTag = GetSubMeshOnEdgeTag();
569 aRootName = "SubMeshes on Edge";
572 aRootTag = GetSubMeshOnWireTag();
573 aRootName = "SubMeshes on Wire";
576 aRootTag = GetSubMeshOnFaceTag();
577 aRootName = "SubMeshes on Face";
580 aRootTag = GetSubMeshOnShellTag();
581 aRootName = "SubMeshes on Shell";
584 aRootTag = GetSubMeshOnSolidTag();
585 aRootName = "SubMeshes on Solid";
588 aRootTag = GetSubMeshOnCompoundTag();
589 aRootName = "SubMeshes on Compound";
593 // Find or create submesh root
594 SALOMEDS::SObject_var aRootSO = publish (theStudy, CORBA::Object::_nil(),
595 aMeshSO, aRootTag, 0, false );
596 SetName( aRootSO, aRootName );
598 // Add new submesh to corresponding sub-tree
599 aSubMeshSO = publish (theStudy, theSubMesh, aRootSO, 0, "ICON_SMESH_TREE_MESH_WARN");
600 if ( aSubMeshSO->_is_nil() )
601 return aSubMeshSO._retn();
603 SetName( aSubMeshSO, theName, "SubMesh" );
605 // Add reference to theShapeObject
607 addReference( theStudy, aSubMeshSO, theShapeObject, 1 );
609 // Publish hypothesis
611 SMESH::ListOfHypothesis * hypList = theMesh->GetHypothesisList( theShapeObject );
613 for ( int i = 0; i < hypList->length(); i++ ) {
614 SMESH::SMESH_Hypothesis_var aHyp = SMESH::SMESH_Hypothesis::_narrow( (*hypList)[ i ]);
615 PublishHypothesis( theStudy, aHyp );
616 AddHypothesisToShape( theStudy, theMesh, theShapeObject, aHyp );
619 return aSubMeshSO._retn();
622 //=======================================================================
623 //function : PublishGroup
625 //=======================================================================
627 SALOMEDS::SObject_ptr SMESH_Gen_i::PublishGroup (SALOMEDS::Study_ptr theStudy,
628 SMESH::SMESH_Mesh_ptr theMesh,
629 SMESH::SMESH_GroupBase_ptr theGroup,
630 GEOM::GEOM_Object_ptr theShapeObject,
633 if (theStudy->_is_nil() || theMesh->_is_nil() || theGroup->_is_nil() )
634 return SALOMEDS::SObject::_nil();
636 SALOMEDS::SObject_var aGroupSO = ObjectToSObject( theStudy, theGroup );
637 if ( aGroupSO->_is_nil() )
639 SALOMEDS::SObject_var aMeshSO = ObjectToSObject( theStudy, theMesh );
640 if ( aMeshSO->_is_nil() ) {
641 aMeshSO = PublishInStudy( theStudy, SALOMEDS::SObject::_nil(), theMesh, "");
642 if ( aMeshSO->_is_nil())
643 return SALOMEDS::SObject::_nil();
645 int aType = (int)theGroup->GetType();
646 const char* aRootNames[] = {
647 "Compound Groups", "Groups of Nodes",
648 "Groups of Edges", "Groups of Faces", "Groups of Volumes" };
650 // Currently, groups with heterogenous content are not supported
651 if ( aType != SMESH::ALL ) {
652 long aRootTag = GetNodeGroupsTag() + aType - 1;
654 // Find or create groups root
655 SALOMEDS::SObject_var aRootSO = publish (theStudy, CORBA::Object::_nil(),
656 aMeshSO, aRootTag, 0, false );
658 SetName( aRootSO, aRootNames[aType] );
660 // Add new group to corresponding sub-tree
661 aGroupSO = publish (theStudy, theGroup, aRootSO, 0, "ICON_SMESH_TREE_GROUP" );
663 if ( aGroupSO->_is_nil() )
664 return aGroupSO._retn();
667 SetName( aGroupSO, theName, "Group" );
669 //Add reference to geometry
670 if ( !theShapeObject->_is_nil() )
671 addReference( theStudy, aGroupSO, theShapeObject, 1 );
673 return aGroupSO._retn();
676 //=======================================================================
677 //function : PublishHypothesis
679 //=======================================================================
681 SALOMEDS::SObject_ptr
682 SMESH_Gen_i::PublishHypothesis (SALOMEDS::Study_ptr theStudy,
683 SMESH::SMESH_Hypothesis_ptr theHyp,
686 if(MYDEBUG) MESSAGE("PublishHypothesis")
687 if (theStudy->_is_nil() || theHyp->_is_nil())
688 return SALOMEDS::SObject::_nil();
690 SALOMEDS::SObject_var aHypSO = ObjectToSObject( theStudy, theHyp );
691 if ( aHypSO->_is_nil() )
693 SALOMEDS::SComponent_var father = PublishComponent( theStudy );
694 if ( father->_is_nil() )
695 return aHypSO._retn();
697 //Find or Create Hypothesis root
698 bool isAlgo = ( !SMESH::SMESH_Algo::_narrow( theHyp )->_is_nil() );
699 int aRootTag = isAlgo ? GetAlgorithmsRootTag() : GetHypothesisRootTag();
700 SALOMEDS::SObject_var aRootSO =
701 publish (theStudy, CORBA::Object::_nil(),father, aRootTag,
702 isAlgo ? "ICON_SMESH_TREE_ALGO" : "ICON_SMESH_TREE_HYPO", false);
703 SetName( aRootSO, isAlgo ? "Algorithms" : "Hypotheses" );
705 // Add New Hypothesis
706 string aPmName = isAlgo ? "ICON_SMESH_TREE_ALGO_" : "ICON_SMESH_TREE_HYPO_";
707 aPmName += theHyp->GetName();
708 aHypSO = publish( theStudy, theHyp, aRootSO, 0, aPmName.c_str() );
711 if ( !aHypSO->_is_nil() ) {
712 CORBA::String_var aHypName = CORBA::string_dup( theHyp->GetName() );
713 SetName( aHypSO, theName, aHypName );
716 if(MYDEBUG) MESSAGE("PublishHypothesis--END")
717 return aHypSO._retn();
720 //=======================================================================
721 //function : GetMeshOrSubmeshByShape
723 //=======================================================================
725 SALOMEDS::SObject_ptr
726 SMESH_Gen_i::GetMeshOrSubmeshByShape (SALOMEDS::Study_ptr theStudy,
727 SMESH::SMESH_Mesh_ptr theMesh,
728 GEOM::GEOM_Object_ptr theShape)
730 if(MYDEBUG) MESSAGE("GetMeshOrSubmeshByShape")
731 SALOMEDS::SObject_var aMeshOrSubMesh;
732 if ( theShape->_is_nil() || theMesh->_is_nil() )
733 return aMeshOrSubMesh._retn();
735 TopoDS_Shape aShape = GeomObjectToShape( theShape );
736 SMESH_Mesh_i* mesh_i = objectToServant<SMESH_Mesh_i>( theMesh );
738 if ( !aShape.IsNull() && mesh_i && mesh_i->GetImpl().GetMeshDS() ) {
739 SMESHDS_Mesh* meshDS = mesh_i->GetImpl().GetMeshDS();
740 if ( aShape.IsSame( meshDS->ShapeToMesh() ))
741 aMeshOrSubMesh = ObjectToSObject( theStudy, theMesh );
743 int shapeID = meshDS->ShapeToIndex( aShape );
744 SMESH::SMESH_subMesh_var aSubMesh = mesh_i->getSubMesh(shapeID);
745 if ( !aSubMesh->_is_nil() )
746 aMeshOrSubMesh = ObjectToSObject( theStudy, aSubMesh );
749 if(MYDEBUG) MESSAGE("GetMeshOrSubmeshByShape--END")
750 return aMeshOrSubMesh._retn();
753 //=======================================================================
754 //function : AddHypothesisToShape
756 //=======================================================================
758 bool SMESH_Gen_i::AddHypothesisToShape(SALOMEDS::Study_ptr theStudy,
759 SMESH::SMESH_Mesh_ptr theMesh,
760 GEOM::GEOM_Object_ptr theShape,
761 SMESH::SMESH_Hypothesis_ptr theHyp)
763 if(MYDEBUG) MESSAGE("AddHypothesisToShape")
764 if (theStudy->_is_nil() || theMesh->_is_nil() ||
765 theHyp->_is_nil() || theShape->_is_nil() )
768 SALOMEDS::SObject_var aMeshSO = ObjectToSObject( theStudy, theMesh );
769 if ( aMeshSO->_is_nil() )
770 aMeshSO = PublishMesh( theStudy, theMesh );
771 SALOMEDS::SObject_var aHypSO = PublishHypothesis( theStudy, theHyp );
772 if ( aMeshSO->_is_nil() || aHypSO->_is_nil())
775 // Find a mesh or submesh refering to theShape
776 SALOMEDS::SObject_var aMeshOrSubMesh =
777 GetMeshOrSubmeshByShape( theStudy, theMesh, theShape );
778 if ( aMeshOrSubMesh->_is_nil() )
781 TopoDS_Shape aShape = GeomObjectToShape( theShape );
782 SMESH_Mesh_i* mesh_i = objectToServant<SMESH_Mesh_i>( theMesh );
783 if ( !aShape.IsNull() && mesh_i && mesh_i->GetImpl().GetMeshDS() ) {
784 SMESHDS_Mesh* meshDS = mesh_i->GetImpl().GetMeshDS();
785 int shapeID = meshDS->ShapeToIndex( aShape );
786 SMESH::SMESH_subMesh_var aSubMesh = mesh_i->getSubMesh(shapeID);
787 aMeshOrSubMesh = PublishSubMesh( theStudy, theMesh, aSubMesh, theShape );
789 if ( aMeshOrSubMesh->_is_nil() )
793 //Find or Create Applied Hypothesis root
794 bool aIsAlgo = !SMESH::SMESH_Algo::_narrow( theHyp )->_is_nil();
795 SALOMEDS::SObject_var AHR =
796 publish (theStudy, CORBA::Object::_nil(), aMeshOrSubMesh,
797 aIsAlgo ? GetRefOnAppliedAlgorithmsTag() : GetRefOnAppliedHypothesisTag(),
798 aIsAlgo ? "ICON_SMESH_TREE_ALGO" : "ICON_SMESH_TREE_HYPO", false);
799 SetName( AHR, aIsAlgo ? "Applied algorithms" : "Applied hypotheses" );
800 if ( AHR->_is_nil() )
803 addReference( theStudy, AHR, theHyp );
804 if(MYDEBUG) MESSAGE("AddHypothesisToShape--END")
808 //=======================================================================
809 //function : RemoveHypothesisFromShape
811 //=======================================================================
813 bool SMESH_Gen_i::RemoveHypothesisFromShape(SALOMEDS::Study_ptr theStudy,
814 SMESH::SMESH_Mesh_ptr theMesh,
815 GEOM::GEOM_Object_ptr theShape,
816 SMESH::SMESH_Hypothesis_ptr theHyp)
818 if (theStudy->_is_nil() || theMesh->_is_nil() ||
819 theHyp->_is_nil() || theShape->_is_nil() )
822 SALOMEDS::SObject_var aHypSO = ObjectToSObject( theStudy, theHyp );
823 if ( aHypSO->_is_nil() )
826 // Find a mesh or submesh refering to theShape
827 SALOMEDS::SObject_var aMeshOrSubMesh =
828 GetMeshOrSubmeshByShape( theStudy, theMesh, theShape );
829 if ( aMeshOrSubMesh->_is_nil() )
832 // Find and remove a reference to aHypSO
833 SALOMEDS::SObject_var aRef, anObj;
834 CORBA::String_var anID = CORBA::string_dup( aHypSO->GetID() );
835 SALOMEDS::ChildIterator_var it = theStudy->NewChildIterator( aMeshOrSubMesh );
836 for ( it->InitEx( true ); it->More(); it->Next() ) {
838 if (anObj->ReferencedObject( aRef ) && strcmp( aRef->GetID(), anID ) == 0 ) {
839 theStudy->NewBuilder()->RemoveObject( anObj );