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"
37 #include CORBA_CLIENT_HEADER(SALOME_ModuleCatalog)
39 #include "utilities.h"
40 #include "Utils_ExceptHandlers.hxx"
42 #include <TCollection_AsciiString.hxx>
45 static int MYDEBUG = 0;
47 static int MYDEBUG = 0;
50 //=============================================================================
52 * Get...Tag [ static ]
54 * Methods which determine SMESH data model structure
56 //=============================================================================
58 long SMESH_Gen_i::GetHypothesisRootTag()
60 return SMESH::Tag_HypothesisRoot;
63 long SMESH_Gen_i::GetAlgorithmsRootTag()
65 return SMESH::Tag_AlgorithmsRoot;
68 long SMESH_Gen_i::GetRefOnShapeTag()
70 return SMESH::Tag_RefOnShape;
73 long SMESH_Gen_i::GetRefOnAppliedHypothesisTag()
75 return SMESH::Tag_RefOnAppliedHypothesis;
78 long SMESH_Gen_i::GetRefOnAppliedAlgorithmsTag()
80 return SMESH::Tag_RefOnAppliedAlgorithms;
83 long SMESH_Gen_i::GetSubMeshOnVertexTag()
85 return SMESH::Tag_SubMeshOnVertex;
88 long SMESH_Gen_i::GetSubMeshOnEdgeTag()
90 return SMESH::Tag_SubMeshOnEdge;
93 long SMESH_Gen_i::GetSubMeshOnFaceTag()
95 return SMESH::Tag_SubMeshOnFace;
98 long SMESH_Gen_i::GetSubMeshOnSolidTag()
100 return SMESH::Tag_SubMeshOnSolid;
103 long SMESH_Gen_i::GetSubMeshOnCompoundTag()
105 return SMESH::Tag_SubMeshOnCompound;
108 long SMESH_Gen_i::GetSubMeshOnWireTag()
110 return SMESH::Tag_SubMeshOnWire;
113 long SMESH_Gen_i::GetSubMeshOnShellTag()
115 return SMESH::Tag_SubMeshOnShell;
118 long SMESH_Gen_i::GetNodeGroupsTag()
120 return SMESH::Tag_NodeGroups;
123 long SMESH_Gen_i::GetEdgeGroupsTag()
125 return SMESH::Tag_EdgeGroups;
128 long SMESH_Gen_i::GetFaceGroupsTag()
130 return SMESH::Tag_FaceGroups;
133 long SMESH_Gen_i::GetVolumeGroupsTag()
135 return SMESH::Tag_VolumeGroups;
138 //=============================================================================
140 * SMESH_Gen_i::CanPublishInStudy
142 * Returns true if object can be published in the study
144 //=============================================================================
146 bool SMESH_Gen_i::CanPublishInStudy(CORBA::Object_ptr theIOR)
148 if(MYDEBUG) MESSAGE("CanPublishInStudy - "<<!CORBA::is_nil(myCurrentStudy));
149 if(CORBA::is_nil(myCurrentStudy))
152 SMESH::SMESH_Mesh_var aMesh = SMESH::SMESH_Mesh::_narrow(theIOR);
153 if( !aMesh->_is_nil() )
156 SMESH::SMESH_subMesh_var aSubMesh = SMESH::SMESH_subMesh::_narrow(theIOR);
157 if( !aSubMesh->_is_nil() )
160 SMESH::SMESH_Hypothesis_var aHyp = SMESH::SMESH_Hypothesis::_narrow(theIOR);
161 if( !aHyp->_is_nil() )
164 SMESH::SMESH_GroupBase_var aGroup = SMESH::SMESH_GroupBase::_narrow(theIOR);
165 if( !aGroup->_is_nil() )
168 if(MYDEBUG) MESSAGE("CanPublishInStudy--CANT");
172 //=======================================================================
173 //function : ObjectToSObject
175 //=======================================================================
177 SALOMEDS::SObject_ptr SMESH_Gen_i::ObjectToSObject(SALOMEDS::Study_ptr theStudy,
178 CORBA::Object_ptr theObject)
180 SALOMEDS::SObject_var aSO;
181 if ( !CORBA::is_nil( theStudy ) && !CORBA::is_nil( theObject ))
183 CORBA::String_var objStr = SMESH_Gen_i::GetORB()->object_to_string( theObject );
184 aSO = theStudy->FindObjectIOR( objStr.in() );
189 //=======================================================================
190 //function : objectToServant
192 //=======================================================================
194 template<typename T> static inline T* objectToServant( CORBA::Object_ptr theIOR )
196 return dynamic_cast<T*>( SMESH_Gen_i::GetServant( theIOR ).in() );
199 //=======================================================================
200 //function : ShapeToGeomObject
202 //=======================================================================
204 GEOM::GEOM_Object_ptr SMESH_Gen_i::ShapeToGeomObject (const TopoDS_Shape& theShape )
206 GEOM::GEOM_Object_var aShapeObj;
207 if ( !theShape.IsNull() ) {
208 GEOM_Client* aClient = GetShapeReader();
209 TCollection_AsciiString IOR;
210 if ( aClient && aClient->Find( theShape, IOR ))
211 aShapeObj = GEOM::GEOM_Object::_narrow
212 ( GetORB()->string_to_object( IOR.ToCString() ) );
214 return aShapeObj._retn();
217 //=======================================================================
218 //function : GeomObjectToShape
220 //=======================================================================
222 TopoDS_Shape SMESH_Gen_i::GeomObjectToShape(GEOM::GEOM_Object_ptr theGeomObject)
225 if ( !theGeomObject->_is_nil() ) {
226 GEOM_Client* aClient = GetShapeReader();
227 GEOM::GEOM_Gen_ptr aGeomEngine = GetGeomEngine();
228 if ( aClient && !aGeomEngine->_is_nil () )
229 S = aClient->GetShape( aGeomEngine, theGeomObject );
234 //=======================================================================
237 //=======================================================================
239 static SALOMEDS::SObject_ptr publish(SALOMEDS::Study_ptr theStudy,
240 CORBA::Object_ptr theIOR,
241 SALOMEDS::SObject_ptr theFatherObject,
242 const int theTag = 0,
243 const char* thePixMap = 0,
244 const bool theSelectable = true)
246 SALOMEDS::SObject_var SO = SMESH_Gen_i::ObjectToSObject( theStudy, theIOR );
247 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
248 if ( SO->_is_nil() ) {
250 SO = aStudyBuilder->NewObject( theFatherObject );
251 else if ( !theFatherObject->FindSubObject( theTag, SO ))
252 SO = aStudyBuilder->NewObjectToTag( theFatherObject, theTag );
255 SALOMEDS::GenericAttribute_var anAttr;
256 if ( !CORBA::is_nil( theIOR )) {
257 anAttr = aStudyBuilder->FindOrCreateAttribute( SO, "AttributeIOR" );
258 CORBA::String_var objStr = SMESH_Gen_i::GetORB()->object_to_string( theIOR );
259 SALOMEDS::AttributeIOR::_narrow(anAttr)->SetValue( objStr.in() );
262 anAttr = aStudyBuilder->FindOrCreateAttribute( SO, "AttributePixMap" );
263 SALOMEDS::AttributePixMap::_narrow( anAttr )->SetPixMap( thePixMap );
265 if ( !theSelectable ) {
266 anAttr = aStudyBuilder->FindOrCreateAttribute( SO, "AttributeSelectable" );
267 SALOMEDS::AttributeSelectable::_narrow( anAttr )->SetSelectable( false );
272 //=======================================================================
275 //=======================================================================
277 void SMESH_Gen_i::SetName(SALOMEDS::SObject_ptr theSObject,
279 const char* theDefaultName)
281 if ( !theSObject->_is_nil() ) {
282 SALOMEDS::StudyBuilder_var aStudyBuilder = theSObject->GetStudy()->NewBuilder();
283 SALOMEDS::GenericAttribute_var anAttr =
284 aStudyBuilder->FindOrCreateAttribute( theSObject, "AttributeName" );
285 SALOMEDS::AttributeName_var aNameAttr = SALOMEDS::AttributeName::_narrow( anAttr );
286 if ( theName && strlen( theName ) != 0 )
287 aNameAttr->SetValue( theName );
289 CORBA::String_var curName = CORBA::string_dup( aNameAttr->Value() );
290 if ( strlen( curName ) == 0 ) {
291 TCollection_AsciiString aName( (char*) theDefaultName );
292 aName += TCollection_AsciiString("_") + TCollection_AsciiString( theSObject->Tag() );
293 aNameAttr->SetValue( aName.ToCString() );
299 //=======================================================================
300 //function : addReference
302 //=======================================================================
304 static void addReference (SALOMEDS::Study_ptr theStudy,
305 SALOMEDS::SObject_ptr theSObject,
306 CORBA::Object_ptr theToObject,
309 SALOMEDS::SObject_var aToObjSO = SMESH_Gen_i::ObjectToSObject( theStudy, theToObject );
310 if ( !aToObjSO->_is_nil() && !theSObject->_is_nil() ) {
311 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
312 SALOMEDS::SObject_var aReferenceSO;
314 // check if the reference to theToObject already exists
315 // and find a free label for the reference object
316 bool isReferred = false;
318 SALOMEDS::ChildIterator_var anIter = theStudy->NewChildIterator( theSObject );
319 for ( ; !isReferred && anIter->More(); anIter->Next(), ++tag ) {
320 if ( anIter->Value()->ReferencedObject( aReferenceSO )) {
321 if ( strcmp( aReferenceSO->GetID(), aToObjSO->GetID() ) == 0 )
324 else if ( !theTag ) {
325 SALOMEDS::GenericAttribute_var anAttr;
326 if ( !anIter->Value()->FindAttribute( anAttr, "AttributeIOR" ))
335 if ( !theSObject->FindSubObject( theTag, aReferenceSO ))
336 aReferenceSO = aStudyBuilder->NewObjectToTag( theSObject, theTag );
337 aStudyBuilder->Addreference( aReferenceSO, aToObjSO );
341 //=============================================================================
343 * SMESH_Gen_i::PublishInStudy
345 * Publish object in the study
347 //=============================================================================
349 SALOMEDS::SObject_ptr SMESH_Gen_i::PublishInStudy(SALOMEDS::Study_ptr theStudy,
350 SALOMEDS::SObject_ptr theSObject,
351 CORBA::Object_ptr theIOR,
353 throw (SALOME::SALOME_Exception)
355 Unexpect aCatch(SALOME_SalomeException);
356 SALOMEDS::SObject_var aSO;
357 if ( CORBA::is_nil( theStudy ) || CORBA::is_nil( theIOR ))
359 if(MYDEBUG) MESSAGE("PublishInStudy");
362 SMESH::SMESH_Mesh_var aMesh = SMESH::SMESH_Mesh::_narrow( theIOR );
363 if( !aMesh->_is_nil() )
364 aSO = PublishMesh( theStudy, aMesh, theName );
366 // Publishing a sub-mesh
367 SMESH::SMESH_subMesh_var aSubMesh = SMESH::SMESH_subMesh::_narrow( theIOR );
368 if( aSO->_is_nil() && !aSubMesh->_is_nil() ) {
369 GEOM::GEOM_Object_var aShapeObject = aSubMesh->GetSubShape();
370 aMesh = aSubMesh->GetFather();
371 aSO = PublishSubMesh( theStudy, aMesh, aSubMesh, aShapeObject, theName );
374 // Publishing a hypothesis or algorithm
375 SMESH::SMESH_Hypothesis_var aHyp = SMESH::SMESH_Hypothesis::_narrow( theIOR );
376 if ( aSO->_is_nil() && !aHyp->_is_nil() )
377 aSO = PublishHypothesis( theStudy, aHyp );
379 // Publishing a group
380 SMESH::SMESH_GroupBase_var aGroup = SMESH::SMESH_GroupBase::_narrow(theIOR);
381 if ( aSO->_is_nil() && !aGroup->_is_nil() ) {
382 GEOM::GEOM_Object_var aShapeObject;
383 aMesh = aGroup->GetMesh();
384 aSO = PublishGroup( theStudy, aMesh, aGroup, aShapeObject, theName );
386 if(MYDEBUG) MESSAGE("PublishInStudy_END");
391 //=======================================================================
392 //function : PublishComponent
394 //=======================================================================
396 SALOMEDS::SComponent_ptr SMESH_Gen_i::PublishComponent(SALOMEDS::Study_ptr theStudy)
398 if ( CORBA::is_nil( theStudy ))
399 return SALOMEDS::SComponent::_nil();
400 if(MYDEBUG) MESSAGE("PublishComponent");
402 SALOMEDS::SComponent_var father =
403 SALOMEDS::SComponent::_narrow( theStudy->FindComponent( ComponentDataType() ) );
404 if ( !CORBA::is_nil( father ) )
405 return father._retn();
407 SALOME_ModuleCatalog::ModuleCatalog_var aCat =
408 SALOME_ModuleCatalog::ModuleCatalog::_narrow( GetNS()->Resolve("/Kernel/ModulCatalog") );
409 if ( CORBA::is_nil( aCat ) )
410 return father._retn();
412 SALOME_ModuleCatalog::Acomponent_var aComp = aCat->GetComponent( ComponentDataType() );
413 if ( CORBA::is_nil( aComp ) )
414 return father._retn();
416 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
417 SALOMEDS::GenericAttribute_var anAttr;
418 SALOMEDS::AttributePixMap_var aPixmap;
420 father = aStudyBuilder->NewComponent( ComponentDataType() );
421 aStudyBuilder->DefineComponentInstance( father, SMESH_Gen::_this() );
422 anAttr = aStudyBuilder->FindOrCreateAttribute( father, "AttributePixMap" );
423 aPixmap = SALOMEDS::AttributePixMap::_narrow( anAttr );
424 aPixmap ->SetPixMap( "ICON_OBJBROWSER_SMESH" );
425 SetName( father, aComp->componentusername(), "MESH" );
426 if(MYDEBUG) MESSAGE("PublishComponent--END");
428 return father._retn();
431 //=============================================================================
433 * findMaxChildTag [ static internal ]
435 * Finds maximum child tag for the given object
437 //=============================================================================
439 static long findMaxChildTag( SALOMEDS::SObject_ptr theSObject )
442 if ( !theSObject->_is_nil() ) {
443 SALOMEDS::Study_var aStudy = theSObject->GetStudy();
444 if ( !aStudy->_is_nil() ) {
445 SALOMEDS::ChildIterator_var anIter = aStudy->NewChildIterator( theSObject );
446 for ( ; anIter->More(); anIter->Next() ) {
447 long nTag = anIter->Value()->Tag();
456 //=======================================================================
457 //function : PublishMesh
459 //=======================================================================
461 SALOMEDS::SObject_ptr SMESH_Gen_i::PublishMesh (SALOMEDS::Study_ptr theStudy,
462 SMESH::SMESH_Mesh_ptr theMesh,
465 if ( CORBA::is_nil( theStudy ) ||
466 CORBA::is_nil( theMesh ))
467 return SALOMEDS::SComponent::_nil();
468 if(MYDEBUG) MESSAGE("PublishMesh--IN");
470 // find or publish a mesh
472 SALOMEDS::SObject_var aMeshSO = ObjectToSObject( theStudy, theMesh );
473 if ( aMeshSO->_is_nil() )
475 SALOMEDS::SComponent_var father = PublishComponent( theStudy );
476 if ( father->_is_nil() )
477 return aMeshSO._retn();
479 // Find correct free tag
480 long aTag = findMaxChildTag( father.in() );
481 if ( aTag <= GetAlgorithmsRootTag() )
482 aTag = GetAlgorithmsRootTag() + 1;
486 aMeshSO = publish (theStudy, theMesh, father, aTag, "ICON_SMESH_TREE_MESH_WARN" );
487 if ( aMeshSO->_is_nil() )
488 return aMeshSO._retn();
490 SetName( aMeshSO, theName, "Mesh" );
492 // Add shape reference
494 GEOM::GEOM_Object_var aShapeObject = theMesh->GetShapeToMesh();
495 if ( !CORBA::is_nil( aShapeObject )) {
496 addReference( theStudy, aMeshSO, aShapeObject, GetRefOnShapeTag() );
498 // Publish global hypotheses
500 SMESH::ListOfHypothesis * hypList = theMesh->GetHypothesisList( aShapeObject );
502 for ( int i = 0; i < hypList->length(); i++ ) {
503 SMESH::SMESH_Hypothesis_var aHyp = SMESH::SMESH_Hypothesis::_narrow( (*hypList)[ i ]);
504 PublishHypothesis( theStudy, aHyp );
505 AddHypothesisToShape( theStudy, theMesh, aShapeObject, aHyp );
511 SMESH_Mesh_i* mesh_i = objectToServant<SMESH_Mesh_i>( theMesh );
513 return aMeshSO._retn();
514 map<int, SMESH_subMesh_i*>& subMap = mesh_i->_mapSubMesh_i;
515 map<int, SMESH_subMesh_i*>::iterator subIt = subMap.begin();
516 for ( ; subIt != subMap.end(); subIt++ ) {
517 SMESH::SMESH_subMesh_ptr aSubMesh = (*subIt).second->_this();
518 if ( !CORBA::is_nil( aSubMesh )) {
519 aShapeObject = aSubMesh->GetSubShape();
520 PublishSubMesh( theStudy, theMesh, aSubMesh, aShapeObject );
525 const map<int, SMESH::SMESH_GroupBase_ptr>& grMap = mesh_i->getGroups();
526 map<int, SMESH::SMESH_GroupBase_ptr>::const_iterator it = grMap.begin();
527 for ( ; it != grMap.end(); it++ )
529 SMESH::SMESH_GroupBase_ptr aGroup = (*it).second;
530 if ( !aGroup->_is_nil() ) {
531 GEOM::GEOM_Object_var aShapeObj;
532 SMESH::SMESH_GroupOnGeom_var aGeomGroup =
533 SMESH::SMESH_GroupOnGeom::_narrow( aGroup );
534 if ( !aGeomGroup->_is_nil() )
535 aShapeObj = aGeomGroup->GetShape();
536 PublishGroup( theStudy, theMesh, aGroup, aShapeObj );
540 if(MYDEBUG) MESSAGE("PublishMesh_END");
541 return aMeshSO._retn();
544 //=======================================================================
545 //function : PublishSubMesh
547 //=======================================================================
549 SALOMEDS::SObject_ptr SMESH_Gen_i::PublishSubMesh (SALOMEDS::Study_ptr theStudy,
550 SMESH::SMESH_Mesh_ptr theMesh,
551 SMESH::SMESH_subMesh_ptr theSubMesh,
552 GEOM::GEOM_Object_ptr theShapeObject,
555 if (theStudy->_is_nil() || theMesh->_is_nil() ||
556 theSubMesh->_is_nil() || theShapeObject->_is_nil() )
557 return SALOMEDS::SObject::_nil();
559 SALOMEDS::SObject_var aSubMeshSO = ObjectToSObject( theStudy, theSubMesh );
560 if ( aSubMeshSO->_is_nil() )
562 SALOMEDS::SObject_var aMeshSO = ObjectToSObject( theStudy, theMesh );
563 if ( aMeshSO->_is_nil() ) {
564 aMeshSO = PublishMesh( theStudy, theMesh );
565 if ( aMeshSO->_is_nil())
566 return SALOMEDS::SObject::_nil();
568 // Find submesh sub-tree tag
570 char* aRootName = "";
571 switch ( theShapeObject->GetShapeType() ) {
573 aRootTag = GetSubMeshOnVertexTag();
574 aRootName = "SubMeshes on Vertex";
577 aRootTag = GetSubMeshOnEdgeTag();
578 aRootName = "SubMeshes on Edge";
581 aRootTag = GetSubMeshOnWireTag();
582 aRootName = "SubMeshes on Wire";
585 aRootTag = GetSubMeshOnFaceTag();
586 aRootName = "SubMeshes on Face";
589 aRootTag = GetSubMeshOnShellTag();
590 aRootName = "SubMeshes on Shell";
593 aRootTag = GetSubMeshOnSolidTag();
594 aRootName = "SubMeshes on Solid";
597 aRootTag = GetSubMeshOnCompoundTag();
598 aRootName = "SubMeshes on Compound";
602 // Find or create submesh root
603 SALOMEDS::SObject_var aRootSO = publish (theStudy, CORBA::Object::_nil(),
604 aMeshSO, aRootTag, 0, false );
605 SetName( aRootSO, aRootName );
607 // Add new submesh to corresponding sub-tree
608 aSubMeshSO = publish (theStudy, theSubMesh, aRootSO, 0, "ICON_SMESH_TREE_MESH_WARN");
609 if ( aSubMeshSO->_is_nil() )
610 return aSubMeshSO._retn();
612 SetName( aSubMeshSO, theName, "SubMesh" );
614 // Add reference to theShapeObject
616 addReference( theStudy, aSubMeshSO, theShapeObject, 1 );
618 // Publish hypothesis
620 SMESH::ListOfHypothesis * hypList = theMesh->GetHypothesisList( theShapeObject );
622 for ( int i = 0; i < hypList->length(); i++ ) {
623 SMESH::SMESH_Hypothesis_var aHyp = SMESH::SMESH_Hypothesis::_narrow( (*hypList)[ i ]);
624 PublishHypothesis( theStudy, aHyp );
625 AddHypothesisToShape( theStudy, theMesh, theShapeObject, aHyp );
628 return aSubMeshSO._retn();
631 //=======================================================================
632 //function : PublishGroup
634 //=======================================================================
636 SALOMEDS::SObject_ptr SMESH_Gen_i::PublishGroup (SALOMEDS::Study_ptr theStudy,
637 SMESH::SMESH_Mesh_ptr theMesh,
638 SMESH::SMESH_GroupBase_ptr theGroup,
639 GEOM::GEOM_Object_ptr theShapeObject,
642 if (theStudy->_is_nil() || theMesh->_is_nil() || theGroup->_is_nil() )
643 return SALOMEDS::SObject::_nil();
645 SALOMEDS::SObject_var aGroupSO = ObjectToSObject( theStudy, theGroup );
646 if ( aGroupSO->_is_nil() )
648 SALOMEDS::SObject_var aMeshSO = ObjectToSObject( theStudy, theMesh );
649 if ( aMeshSO->_is_nil() ) {
650 aMeshSO = PublishInStudy( theStudy, SALOMEDS::SObject::_nil(), theMesh, "");
651 if ( aMeshSO->_is_nil())
652 return SALOMEDS::SObject::_nil();
654 int aType = (int)theGroup->GetType();
655 const char* aRootNames[] = {
656 "Compound Groups", "Groups of Nodes",
657 "Groups of Edges", "Groups of Faces", "Groups of Volumes" };
659 // Currently, groups with heterogenous content are not supported
660 if ( aType != SMESH::ALL ) {
661 long aRootTag = GetNodeGroupsTag() + aType - 1;
663 // Find or create groups root
664 SALOMEDS::SObject_var aRootSO = publish (theStudy, CORBA::Object::_nil(),
665 aMeshSO, aRootTag, 0, false );
667 SetName( aRootSO, aRootNames[aType] );
669 // Add new group to corresponding sub-tree
670 aGroupSO = publish (theStudy, theGroup, aRootSO, 0, "ICON_SMESH_TREE_GROUP" );
672 if ( aGroupSO->_is_nil() )
673 return aGroupSO._retn();
676 SetName( aGroupSO, theName, "Group" );
678 //Add reference to geometry
679 if ( !theShapeObject->_is_nil() )
680 addReference( theStudy, aGroupSO, theShapeObject, 1 );
682 return aGroupSO._retn();
685 //=======================================================================
686 //function : PublishHypothesis
688 //=======================================================================
690 SALOMEDS::SObject_ptr
691 SMESH_Gen_i::PublishHypothesis (SALOMEDS::Study_ptr theStudy,
692 SMESH::SMESH_Hypothesis_ptr theHyp,
695 if(MYDEBUG) MESSAGE("PublishHypothesis")
696 if (theStudy->_is_nil() || theHyp->_is_nil())
697 return SALOMEDS::SObject::_nil();
699 SALOMEDS::SObject_var aHypSO = ObjectToSObject( theStudy, theHyp );
700 if ( aHypSO->_is_nil() )
702 SALOMEDS::SComponent_var father = PublishComponent( theStudy );
703 if ( father->_is_nil() )
704 return aHypSO._retn();
706 //Find or Create Hypothesis root
707 bool isAlgo = ( !SMESH::SMESH_Algo::_narrow( theHyp )->_is_nil() );
708 int aRootTag = isAlgo ? GetAlgorithmsRootTag() : GetHypothesisRootTag();
709 SALOMEDS::SObject_var aRootSO =
710 publish (theStudy, CORBA::Object::_nil(),father, aRootTag,
711 isAlgo ? "ICON_SMESH_TREE_ALGO" : "ICON_SMESH_TREE_HYPO", false);
712 SetName( aRootSO, isAlgo ? "Algorithms" : "Hypotheses" );
714 // Add New Hypothesis
715 string aPmName = isAlgo ? "ICON_SMESH_TREE_ALGO_" : "ICON_SMESH_TREE_HYPO_";
716 aPmName += theHyp->GetName();
717 // prepend plugin name to pixmap name
718 string pluginName = myHypCreatorMap[string(theHyp->GetName())]->GetModuleName();
719 if ( pluginName != "StdMeshers" )
720 aPmName = pluginName + "::" + aPmName;
721 aHypSO = publish( theStudy, theHyp, aRootSO, 0, aPmName.c_str() );
724 if ( !aHypSO->_is_nil() ) {
725 CORBA::String_var aHypName = CORBA::string_dup( theHyp->GetName() );
726 SetName( aHypSO, theName, aHypName );
729 if(MYDEBUG) MESSAGE("PublishHypothesis--END")
730 return aHypSO._retn();
733 //=======================================================================
734 //function : GetMeshOrSubmeshByShape
736 //=======================================================================
738 SALOMEDS::SObject_ptr
739 SMESH_Gen_i::GetMeshOrSubmeshByShape (SALOMEDS::Study_ptr theStudy,
740 SMESH::SMESH_Mesh_ptr theMesh,
741 GEOM::GEOM_Object_ptr theShape)
743 if(MYDEBUG) MESSAGE("GetMeshOrSubmeshByShape")
744 SALOMEDS::SObject_var aMeshOrSubMesh;
745 if (theMesh->_is_nil() || ( theShape->_is_nil() && theMesh->HasShapeToMesh()))
746 return aMeshOrSubMesh._retn();
749 if(theMesh->HasShapeToMesh())
750 aShape = GeomObjectToShape( theShape );
752 aShape = SMESH_Mesh::PseudoShape();
754 SMESH_Mesh_i* mesh_i = objectToServant<SMESH_Mesh_i>( theMesh );
756 if ( !aShape.IsNull() && mesh_i && mesh_i->GetImpl().GetMeshDS() ) {
757 SMESHDS_Mesh* meshDS = mesh_i->GetImpl().GetMeshDS();
758 if ( aShape.IsSame( meshDS->ShapeToMesh() ))
759 aMeshOrSubMesh = ObjectToSObject( theStudy, theMesh );
761 int shapeID = meshDS->ShapeToIndex( aShape );
762 SMESH::SMESH_subMesh_var aSubMesh = mesh_i->getSubMesh(shapeID);
763 if ( !aSubMesh->_is_nil() )
764 aMeshOrSubMesh = ObjectToSObject( theStudy, aSubMesh );
767 if(MYDEBUG) MESSAGE("GetMeshOrSubmeshByShape--END")
768 return aMeshOrSubMesh._retn();
771 //=======================================================================
772 //function : AddHypothesisToShape
774 //=======================================================================
776 bool SMESH_Gen_i::AddHypothesisToShape(SALOMEDS::Study_ptr theStudy,
777 SMESH::SMESH_Mesh_ptr theMesh,
778 GEOM::GEOM_Object_ptr theShape,
779 SMESH::SMESH_Hypothesis_ptr theHyp)
781 if(MYDEBUG) MESSAGE("AddHypothesisToShape")
782 if (theStudy->_is_nil() || theMesh->_is_nil() ||
783 theHyp->_is_nil() || (theShape->_is_nil()
784 && theMesh->HasShapeToMesh()) )
787 SALOMEDS::SObject_var aMeshSO = ObjectToSObject( theStudy, theMesh );
788 if ( aMeshSO->_is_nil() )
789 aMeshSO = PublishMesh( theStudy, theMesh );
790 SALOMEDS::SObject_var aHypSO = PublishHypothesis( theStudy, theHyp );
791 if ( aMeshSO->_is_nil() || aHypSO->_is_nil())
794 // Find a mesh or submesh refering to theShape
795 SALOMEDS::SObject_var aMeshOrSubMesh =
796 GetMeshOrSubmeshByShape( theStudy, theMesh, theShape );
797 if ( aMeshOrSubMesh->_is_nil() )
800 TopoDS_Shape aShape = GeomObjectToShape( theShape );
801 SMESH_Mesh_i* mesh_i = objectToServant<SMESH_Mesh_i>( theMesh );
802 if ( !aShape.IsNull() && mesh_i && mesh_i->GetImpl().GetMeshDS() ) {
803 SMESHDS_Mesh* meshDS = mesh_i->GetImpl().GetMeshDS();
804 int shapeID = meshDS->ShapeToIndex( aShape );
805 SMESH::SMESH_subMesh_var aSubMesh = mesh_i->getSubMesh(shapeID);
806 aMeshOrSubMesh = PublishSubMesh( theStudy, theMesh, aSubMesh, theShape );
808 if ( aMeshOrSubMesh->_is_nil() )
812 //Find or Create Applied Hypothesis root
813 bool aIsAlgo = !SMESH::SMESH_Algo::_narrow( theHyp )->_is_nil();
814 SALOMEDS::SObject_var AHR =
815 publish (theStudy, CORBA::Object::_nil(), aMeshOrSubMesh,
816 aIsAlgo ? GetRefOnAppliedAlgorithmsTag() : GetRefOnAppliedHypothesisTag(),
817 aIsAlgo ? "ICON_SMESH_TREE_ALGO" : "ICON_SMESH_TREE_HYPO", false);
818 SetName( AHR, aIsAlgo ? "Applied algorithms" : "Applied hypotheses" );
819 if ( AHR->_is_nil() )
822 addReference( theStudy, AHR, theHyp );
823 if(MYDEBUG) MESSAGE("AddHypothesisToShape--END")
827 //=======================================================================
828 //function : RemoveHypothesisFromShape
830 //=======================================================================
832 bool SMESH_Gen_i::RemoveHypothesisFromShape(SALOMEDS::Study_ptr theStudy,
833 SMESH::SMESH_Mesh_ptr theMesh,
834 GEOM::GEOM_Object_ptr theShape,
835 SMESH::SMESH_Hypothesis_ptr theHyp)
837 if (theStudy->_is_nil() || theMesh->_is_nil() ||
838 theHyp->_is_nil() || (theShape->_is_nil()
839 && theMesh->HasShapeToMesh()))
842 SALOMEDS::SObject_var aHypSO = ObjectToSObject( theStudy, theHyp );
843 if ( aHypSO->_is_nil() )
846 // Find a mesh or submesh refering to theShape
847 SALOMEDS::SObject_var aMeshOrSubMesh =
848 GetMeshOrSubmeshByShape( theStudy, theMesh, theShape );
849 if ( aMeshOrSubMesh->_is_nil() )
852 // Find and remove a reference to aHypSO
853 SALOMEDS::SObject_var aRef, anObj;
854 CORBA::String_var anID = CORBA::string_dup( aHypSO->GetID() );
855 SALOMEDS::ChildIterator_var it = theStudy->NewChildIterator( aMeshOrSubMesh );
856 for ( it->InitEx( true ); it->More(); it->Next() ) {
858 if (anObj->ReferencedObject( aRef ) && strcmp( aRef->GetID(), anID ) == 0 ) {
859 theStudy->NewBuilder()->RemoveObject( anObj );