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");
150 SMESH::SMESH_Mesh_var aMesh = SMESH::SMESH_Mesh::_narrow(theIOR);
151 if( !aMesh->_is_nil() )
154 SMESH::SMESH_subMesh_var aSubMesh = SMESH::SMESH_subMesh::_narrow(theIOR);
155 if( !aSubMesh->_is_nil() )
158 SMESH::SMESH_Hypothesis_var aHyp = SMESH::SMESH_Hypothesis::_narrow(theIOR);
159 if( !aHyp->_is_nil() )
162 SMESH::SMESH_GroupBase_var aGroup = SMESH::SMESH_GroupBase::_narrow(theIOR);
163 if( !aGroup->_is_nil() )
166 if(MYDEBUG) MESSAGE("CanPublishInStudy--CANT");
170 //=======================================================================
171 //function : ObjectToSObject
173 //=======================================================================
175 SALOMEDS::SObject_ptr SMESH_Gen_i::ObjectToSObject(SALOMEDS::Study_ptr theStudy,
176 CORBA::Object_ptr theObject)
178 SALOMEDS::SObject_var aSO;
179 if ( !CORBA::is_nil( theStudy ) && !CORBA::is_nil( theObject ))
180 aSO = theStudy->FindObjectIOR( SMESH_Gen_i::GetORB()->object_to_string( theObject ) );
184 //=======================================================================
185 //function : objectToServant
187 //=======================================================================
189 template<typename T> static inline T* objectToServant( CORBA::Object_ptr theIOR )
191 return dynamic_cast<T*>( SMESH_Gen_i::GetServant( theIOR ).in() );
194 //=======================================================================
195 //function : ShapeToGeomObject
197 //=======================================================================
199 GEOM::GEOM_Object_ptr SMESH_Gen_i::ShapeToGeomObject (const TopoDS_Shape& theShape )
201 GEOM::GEOM_Object_var aShapeObj;
202 if ( !theShape.IsNull() ) {
203 GEOM_Client* aClient = GetShapeReader();
204 TCollection_AsciiString IOR;
205 if ( aClient && aClient->Find( theShape, IOR ))
206 aShapeObj = GEOM::GEOM_Object::_narrow
207 ( GetORB()->string_to_object( IOR.ToCString() ) );
209 return aShapeObj._retn();
212 //=======================================================================
213 //function : GeomObjectToShape
215 //=======================================================================
217 TopoDS_Shape SMESH_Gen_i::GeomObjectToShape(GEOM::GEOM_Object_ptr theGeomObject)
220 if ( !theGeomObject->_is_nil() ) {
221 GEOM_Client* aClient = GetShapeReader();
222 GEOM::GEOM_Gen_var aGeomEngine = GetGeomEngine();
223 if ( aClient && !aGeomEngine->_is_nil () )
224 S = aClient->GetShape( aGeomEngine, theGeomObject );
229 //=======================================================================
232 //=======================================================================
234 static SALOMEDS::SObject_ptr publish(SALOMEDS::Study_ptr theStudy,
235 CORBA::Object_ptr theIOR,
236 SALOMEDS::SObject_ptr theFatherObject,
237 const int theTag = 0,
238 const char* thePixMap = 0,
239 const bool theSelectable = true)
241 SALOMEDS::SObject_var SO = SMESH_Gen_i::ObjectToSObject( theStudy, theIOR );
242 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
243 if ( SO->_is_nil() ) {
245 SO = aStudyBuilder->NewObject( theFatherObject );
246 else if ( !theFatherObject->FindSubObject( theTag, SO ))
247 SO = aStudyBuilder->NewObjectToTag( theFatherObject, theTag );
250 SALOMEDS::GenericAttribute_var anAttr;
251 if ( !CORBA::is_nil( theIOR )) {
252 anAttr = aStudyBuilder->FindOrCreateAttribute( SO, "AttributeIOR" );
253 SALOMEDS::AttributeIOR::_narrow(anAttr)->SetValue
254 ( SMESH_Gen_i::GetORB()->object_to_string( theIOR ) );
257 anAttr = aStudyBuilder->FindOrCreateAttribute( SO, "AttributePixMap" );
258 SALOMEDS::AttributePixMap::_narrow( anAttr )->SetPixMap( thePixMap );
260 if ( !theSelectable ) {
261 anAttr = aStudyBuilder->FindOrCreateAttribute( SO, "AttributeSelectable" );
262 SALOMEDS::AttributeSelectable::_narrow( anAttr )->SetSelectable( false );
267 //=======================================================================
270 //=======================================================================
272 void SMESH_Gen_i::SetName(SALOMEDS::SObject_ptr theSObject,
274 const char* theDefaultName)
276 if ( !theSObject->_is_nil() ) {
277 SALOMEDS::StudyBuilder_var aStudyBuilder = theSObject->GetStudy()->NewBuilder();
278 SALOMEDS::GenericAttribute_var anAttr =
279 aStudyBuilder->FindOrCreateAttribute( theSObject, "AttributeName" );
280 SALOMEDS::AttributeName_var aNameAttr = SALOMEDS::AttributeName::_narrow( anAttr );
281 if ( theName && strlen( theName ) != 0 )
282 aNameAttr->SetValue( theName );
284 CORBA::String_var curName = CORBA::string_dup( aNameAttr->Value() );
285 if ( strlen( curName ) == 0 ) {
286 TCollection_AsciiString aName( (char*) theDefaultName );
287 aName += TCollection_AsciiString("_") + TCollection_AsciiString( theSObject->Tag() );
288 aNameAttr->SetValue( aName.ToCString() );
294 //=======================================================================
295 //function : addReference
297 //=======================================================================
299 static void addReference (SALOMEDS::Study_ptr theStudy,
300 SALOMEDS::SObject_ptr theSObject,
301 CORBA::Object_ptr theToObject,
304 SALOMEDS::SObject_var aToObjSO = SMESH_Gen_i::ObjectToSObject( theStudy, theToObject );
305 if ( !aToObjSO->_is_nil() && !theSObject->_is_nil() ) {
306 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
307 SALOMEDS::SObject_var aReferenceSO;
309 bool isReferred = false;
310 SALOMEDS::ChildIterator_var anIter = theStudy->NewChildIterator( theSObject );
311 for ( ; !isReferred && anIter->More(); anIter->Next() ) {
312 if ( anIter->Value()->ReferencedObject( aReferenceSO ) &&
313 strcmp( aReferenceSO->GetID(), aToObjSO->GetID() ) == 0 )
317 aReferenceSO = aStudyBuilder->NewObject( theSObject );
318 aStudyBuilder->Addreference( aReferenceSO, aToObjSO );
322 if ( !theSObject->FindSubObject( theTag, aReferenceSO ))
323 aReferenceSO = aStudyBuilder->NewObjectToTag( theSObject, theTag );
324 aStudyBuilder->Addreference( aReferenceSO, aToObjSO );
329 //=============================================================================
331 * SMESH_Gen_i::PublishInStudy
333 * Publish object in the study
335 //=============================================================================
337 SALOMEDS::SObject_ptr SMESH_Gen_i::PublishInStudy(SALOMEDS::Study_ptr theStudy,
338 SALOMEDS::SObject_ptr theSObject,
339 CORBA::Object_ptr theIOR,
341 throw (SALOME::SALOME_Exception)
343 Unexpect aCatch(SALOME_SalomeException);
344 SALOMEDS::SObject_var aSO;
345 if ( CORBA::is_nil( theStudy ) || CORBA::is_nil( theIOR ))
347 if(MYDEBUG) MESSAGE("PublishInStudy");
350 SMESH::SMESH_Mesh_var aMesh = SMESH::SMESH_Mesh::_narrow( theIOR );
351 if( !aMesh->_is_nil() )
352 aSO = PublishMesh( theStudy, aMesh, theName );
354 // Publishing a sub-mesh
355 SMESH::SMESH_subMesh_var aSubMesh = SMESH::SMESH_subMesh::_narrow( theIOR );
356 if( aSO->_is_nil() && !aSubMesh->_is_nil() ) {
357 GEOM::GEOM_Object_var aShapeObject = aSubMesh->GetSubShape();
358 aMesh = aSubMesh->GetFather();
359 aSO = PublishSubMesh( theStudy, aMesh, aSubMesh, aShapeObject, theName );
362 // Publishing a hypothesis or algorithm
363 SMESH::SMESH_Hypothesis_var aHyp = SMESH::SMESH_Hypothesis::_narrow( theIOR );
364 if ( aSO->_is_nil() && !aHyp->_is_nil() )
365 aSO = PublishHypothesis( theStudy, aHyp );
367 // Publishing a group
368 SMESH::SMESH_GroupBase_var aGroup = SMESH::SMESH_GroupBase::_narrow(theIOR);
369 if ( aSO->_is_nil() && !aGroup->_is_nil() ) {
370 GEOM::GEOM_Object_var aShapeObject;
371 aMesh = aGroup->GetMesh();
372 aSO = PublishGroup( theStudy, aMesh, aGroup, aShapeObject, theName );
374 if(MYDEBUG) MESSAGE("PublishInStudy_END");
379 //=======================================================================
380 //function : PublishComponent
382 //=======================================================================
384 SALOMEDS::SComponent_ptr SMESH_Gen_i::PublishComponent(SALOMEDS::Study_ptr theStudy)
386 if ( CORBA::is_nil( theStudy ))
387 return SALOMEDS::SComponent::_nil();
388 if(MYDEBUG) MESSAGE("PublishComponent");
390 SALOMEDS::SComponent_var father =
391 SALOMEDS::SComponent::_narrow( theStudy->FindComponent( ComponentDataType() ) );
392 if ( !CORBA::is_nil( father ) )
393 return father._retn();
395 SALOME_ModuleCatalog::ModuleCatalog_var aCat =
396 SALOME_ModuleCatalog::ModuleCatalog::_narrow( GetNS()->Resolve("/Kernel/ModulCatalog") );
397 if ( CORBA::is_nil( aCat ) )
398 return father._retn();
400 SALOME_ModuleCatalog::Acomponent_var aComp = aCat->GetComponent( ComponentDataType() );
401 if ( CORBA::is_nil( aComp ) )
402 return father._retn();
404 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
405 SALOMEDS::GenericAttribute_var anAttr;
406 SALOMEDS::AttributePixMap_var aPixmap;
408 father = aStudyBuilder->NewComponent( ComponentDataType() );
409 aStudyBuilder->DefineComponentInstance( father, SMESH_Gen::_this() );
410 anAttr = aStudyBuilder->FindOrCreateAttribute( father, "AttributePixMap" );
411 aPixmap = SALOMEDS::AttributePixMap::_narrow( anAttr );
412 aPixmap ->SetPixMap( "ICON_OBJBROWSER_SMESH" );
413 SetName( father, aComp->componentusername(), "MESH" );
414 if(MYDEBUG) MESSAGE("PublishComponent--END");
416 return father._retn();
419 //=============================================================================
421 * findMaxChildTag [ static internal ]
423 * Finds maximum child tag for the given object
425 //=============================================================================
427 static long findMaxChildTag( SALOMEDS::SObject_ptr theSObject )
430 if ( !theSObject->_is_nil() ) {
431 SALOMEDS::Study_var aStudy = theSObject->GetStudy();
432 if ( !aStudy->_is_nil() ) {
433 SALOMEDS::ChildIterator_var anIter = aStudy->NewChildIterator( theSObject );
434 for ( ; anIter->More(); anIter->Next() ) {
435 long nTag = anIter->Value()->Tag();
444 //=======================================================================
445 //function : PublishMesh
447 //=======================================================================
449 SALOMEDS::SObject_ptr SMESH_Gen_i::PublishMesh (SALOMEDS::Study_ptr theStudy,
450 SMESH::SMESH_Mesh_ptr theMesh,
453 if ( CORBA::is_nil( theStudy ) ||
454 CORBA::is_nil( theMesh ))
455 return SALOMEDS::SComponent::_nil();
456 if(MYDEBUG) MESSAGE("PublishMesh--IN");
458 // find or publish a mesh
460 SALOMEDS::SObject_var aMeshSO = ObjectToSObject( theStudy, theMesh );
461 if ( aMeshSO->_is_nil() )
463 SALOMEDS::SComponent_var father = PublishComponent( theStudy );
464 if ( father->_is_nil() )
465 return aMeshSO._retn();
467 // Find correct free tag
468 long aTag = findMaxChildTag( father.in() );
469 if ( aTag <= GetAlgorithmsRootTag() )
470 aTag = GetAlgorithmsRootTag() + 1;
474 aMeshSO = publish (theStudy, theMesh, father, aTag, "ICON_SMESH_TREE_MESH" );
475 if ( aMeshSO->_is_nil() )
476 return aMeshSO._retn();
478 SetName( aMeshSO, theName, "Mesh" );
480 // Add shape reference
482 GEOM::GEOM_Object_var aShapeObject = theMesh->GetShapeToMesh();
483 if ( !CORBA::is_nil( aShapeObject )) {
484 addReference( theStudy, aMeshSO, aShapeObject, GetRefOnShapeTag() );
486 // Publish global hypotheses
488 SMESH::ListOfHypothesis * hypList = theMesh->GetHypothesisList( aShapeObject );
490 for ( int i = 0; i < hypList->length(); i++ ) {
491 SMESH::SMESH_Hypothesis_var aHyp = SMESH::SMESH_Hypothesis::_narrow( (*hypList)[ i ]);
492 PublishHypothesis( theStudy, aHyp );
493 AddHypothesisToShape( theStudy, theMesh, aShapeObject, aHyp );
499 SMESH_Mesh_i* mesh_i = objectToServant<SMESH_Mesh_i>( theMesh );
501 return aMeshSO._retn();
502 map<int, SMESH_subMesh_i*>& subMap = mesh_i->_mapSubMesh_i;
503 map<int, SMESH_subMesh_i*>::iterator subIt = subMap.begin();
504 for ( ; subIt != subMap.end(); subIt++ ) {
505 SMESH::SMESH_subMesh_ptr aSubMesh = (*subIt).second->_this();
506 if ( !CORBA::is_nil( aSubMesh )) {
507 aShapeObject = aSubMesh->GetSubShape();
508 PublishSubMesh( theStudy, theMesh, aSubMesh, aShapeObject );
513 const map<int, SMESH::SMESH_GroupBase_ptr>& grMap = mesh_i->getGroups();
514 map<int, SMESH::SMESH_GroupBase_ptr>::const_iterator it = grMap.begin();
515 for ( ; it != grMap.end(); it++ )
517 SMESH::SMESH_GroupBase_ptr aGroup = (*it).second;
518 if ( !aGroup->_is_nil() ) {
519 GEOM::GEOM_Object_var aShapeObj;
520 SMESH::SMESH_GroupOnGeom_var aGeomGroup =
521 SMESH::SMESH_GroupOnGeom::_narrow( aGroup );
522 if ( !aGeomGroup->_is_nil() )
523 aShapeObj = aGeomGroup->GetShape();
524 PublishGroup( theStudy, theMesh, aGroup, aShapeObj );
528 if(MYDEBUG) MESSAGE("PublishMesh_END");
529 return aMeshSO._retn();
532 //=======================================================================
533 //function : PublishSubMesh
535 //=======================================================================
537 SALOMEDS::SObject_ptr SMESH_Gen_i::PublishSubMesh (SALOMEDS::Study_ptr theStudy,
538 SMESH::SMESH_Mesh_ptr theMesh,
539 SMESH::SMESH_subMesh_ptr theSubMesh,
540 GEOM::GEOM_Object_ptr theShapeObject,
543 if (theStudy->_is_nil() || theMesh->_is_nil() ||
544 theSubMesh->_is_nil() || theShapeObject->_is_nil() )
545 return SALOMEDS::SObject::_nil();
547 SALOMEDS::SObject_var aSubMeshSO = ObjectToSObject( theStudy, theSubMesh );
548 if ( aSubMeshSO->_is_nil() )
550 SALOMEDS::SObject_var aMeshSO = ObjectToSObject( theStudy, theMesh );
551 if ( aMeshSO->_is_nil() ) {
552 aMeshSO = PublishMesh( theStudy, theMesh );
553 if ( aMeshSO->_is_nil())
554 return SALOMEDS::SObject::_nil();
556 // Find submesh sub-tree tag
558 char* aRootName = "";
559 switch ( theShapeObject->GetShapeType() ) {
561 aRootTag = GetSubMeshOnVertexTag();
562 aRootName = "SubMeshes on Vertex";
565 aRootTag = GetSubMeshOnEdgeTag();
566 aRootName = "SubMeshes on Edge";
569 aRootTag = GetSubMeshOnWireTag();
570 aRootName = "SubMeshes on Wire";
573 aRootTag = GetSubMeshOnFaceTag();
574 aRootName = "SubMeshes on Face";
577 aRootTag = GetSubMeshOnShellTag();
578 aRootName = "SubMeshes on Shell";
581 aRootTag = GetSubMeshOnSolidTag();
582 aRootName = "SubMeshes on Solid";
585 aRootTag = GetSubMeshOnCompoundTag();
586 aRootName = "SubMeshes on Compound";
590 // Find or create submesh root
591 SALOMEDS::SObject_var aRootSO = publish (theStudy, CORBA::Object::_nil(),
592 aMeshSO, aRootTag, 0, false );
593 SetName( aRootSO, aRootName );
595 // Add new submesh to corresponding sub-tree
596 aSubMeshSO = publish (theStudy, theSubMesh, aRootSO, 0, "ICON_SMESH_TREE_MESH");
597 if ( aSubMeshSO->_is_nil() )
598 return aSubMeshSO._retn();
600 SetName( aSubMeshSO, theName, "SubMesh" );
602 // Add reference to theShapeObject
604 addReference( theStudy, aSubMeshSO, theShapeObject, 1 );
606 // Publish hypothesis
608 SMESH::ListOfHypothesis * hypList = theMesh->GetHypothesisList( theShapeObject );
610 for ( int i = 0; i < hypList->length(); i++ ) {
611 SMESH::SMESH_Hypothesis_var aHyp = SMESH::SMESH_Hypothesis::_narrow( (*hypList)[ i ]);
612 PublishHypothesis( theStudy, aHyp );
613 AddHypothesisToShape( theStudy, theMesh, theShapeObject, aHyp );
616 return aSubMeshSO._retn();
619 //=======================================================================
620 //function : PublishGroup
622 //=======================================================================
624 SALOMEDS::SObject_ptr SMESH_Gen_i::PublishGroup (SALOMEDS::Study_ptr theStudy,
625 SMESH::SMESH_Mesh_ptr theMesh,
626 SMESH::SMESH_GroupBase_ptr theGroup,
627 GEOM::GEOM_Object_ptr theShapeObject,
630 if (theStudy->_is_nil() || theMesh->_is_nil() || theGroup->_is_nil() )
631 return SALOMEDS::SObject::_nil();
633 SALOMEDS::SObject_var aGroupSO = ObjectToSObject( theStudy, theGroup );
634 if ( aGroupSO->_is_nil() )
636 SALOMEDS::SObject_var aMeshSO = ObjectToSObject( theStudy, theMesh );
637 if ( aMeshSO->_is_nil() ) {
638 aMeshSO = PublishInStudy( theStudy, SALOMEDS::SObject::_nil(), theMesh, "");
639 if ( aMeshSO->_is_nil())
640 return SALOMEDS::SObject::_nil();
642 int aType = (int)theGroup->GetType();
643 const char* aRootNames[] = {
644 "Compound Groups", "Groups of Nodes",
645 "Groups of Edges", "Groups of Faces", "Groups of Volumes" };
647 // Currently, groups with heterogenous content are not supported
648 if ( aType != SMESH::ALL ) {
649 long aRootTag = GetNodeGroupsTag() + aType - 1;
651 // Find or create groups root
652 SALOMEDS::SObject_var aRootSO = publish (theStudy, CORBA::Object::_nil(),
653 aMeshSO, aRootTag, 0, false );
655 SetName( aRootSO, aRootNames[aType] );
657 // Add new group to corresponding sub-tree
658 aGroupSO = publish (theStudy, theGroup, aRootSO, 0, "ICON_SMESH_TREE_GROUP" );
660 if ( aGroupSO->_is_nil() )
661 return aGroupSO._retn();
664 SetName( aGroupSO, theName, "Group" );
666 //Add reference to geometry
667 if ( !theShapeObject->_is_nil() )
668 addReference( theStudy, aGroupSO, theShapeObject, 1 );
670 return aGroupSO._retn();
673 //=======================================================================
674 //function : PublishHypothesis
676 //=======================================================================
678 SALOMEDS::SObject_ptr
679 SMESH_Gen_i::PublishHypothesis (SALOMEDS::Study_ptr theStudy,
680 SMESH::SMESH_Hypothesis_ptr theHyp,
683 if(MYDEBUG) MESSAGE("PublishHypothesis")
684 if (theStudy->_is_nil() || theHyp->_is_nil())
685 return SALOMEDS::SObject::_nil();
687 SALOMEDS::SObject_var aHypSO = ObjectToSObject( theStudy, theHyp );
688 if ( aHypSO->_is_nil() )
690 SALOMEDS::SComponent_var father = PublishComponent( theStudy );
691 if ( father->_is_nil() )
692 return aHypSO._retn();
694 //Find or Create Hypothesis root
695 bool isAlgo = ( !SMESH::SMESH_Algo::_narrow( theHyp )->_is_nil() );
696 int aRootTag = isAlgo ? GetAlgorithmsRootTag() : GetHypothesisRootTag();
697 SALOMEDS::SObject_var aRootSO =
698 publish (theStudy, CORBA::Object::_nil(),father, aRootTag,
699 isAlgo ? "ICON_SMESH_TREE_ALGO" : "ICON_SMESH_TREE_HYPO", false);
700 SetName( aRootSO, isAlgo ? "Algorithms" : "Hypotheses" );
702 // Add New Hypothesis
703 string aPmName = isAlgo ? "ICON_SMESH_TREE_ALGO_" : "ICON_SMESH_TREE_HYPO_";
704 aPmName += theHyp->GetName();
705 aHypSO = publish( theStudy, theHyp, aRootSO, 0, aPmName.c_str() );
708 if ( !aHypSO->_is_nil() ) {
709 CORBA::String_var aHypName = CORBA::string_dup( theHyp->GetName() );
710 SetName( aHypSO, theName, aHypName );
713 if(MYDEBUG) MESSAGE("PublishHypothesis--END")
714 return aHypSO._retn();
717 //=======================================================================
718 //function : GetMeshOrSubmeshByShape
720 //=======================================================================
722 SALOMEDS::SObject_ptr
723 SMESH_Gen_i::GetMeshOrSubmeshByShape (SALOMEDS::Study_ptr theStudy,
724 SMESH::SMESH_Mesh_ptr theMesh,
725 GEOM::GEOM_Object_ptr theShape)
727 if(MYDEBUG) MESSAGE("GetMeshOrSubmeshByShape")
728 SALOMEDS::SObject_var aMeshOrSubMesh;
729 if ( theShape->_is_nil() || theMesh->_is_nil() )
730 return aMeshOrSubMesh._retn();
732 TopoDS_Shape aShape = GeomObjectToShape( theShape );
733 SMESH_Mesh_i* mesh_i = objectToServant<SMESH_Mesh_i>( theMesh );
735 if ( !aShape.IsNull() && mesh_i && mesh_i->GetImpl().GetMeshDS() ) {
736 SMESHDS_Mesh* meshDS = mesh_i->GetImpl().GetMeshDS();
737 if ( aShape.IsSame( meshDS->ShapeToMesh() ))
738 aMeshOrSubMesh = ObjectToSObject( theStudy, theMesh );
740 int shapeID = meshDS->ShapeToIndex( aShape );
741 SMESH::SMESH_subMesh_var aSubMesh = mesh_i->getSubMesh(shapeID);
742 if ( !aSubMesh->_is_nil() )
743 aMeshOrSubMesh = ObjectToSObject( theStudy, aSubMesh );
746 if(MYDEBUG) MESSAGE("GetMeshOrSubmeshByShape--END")
747 return aMeshOrSubMesh._retn();
750 //=======================================================================
751 //function : AddHypothesisToShape
753 //=======================================================================
755 bool SMESH_Gen_i::AddHypothesisToShape(SALOMEDS::Study_ptr theStudy,
756 SMESH::SMESH_Mesh_ptr theMesh,
757 GEOM::GEOM_Object_ptr theShape,
758 SMESH::SMESH_Hypothesis_ptr theHyp)
760 if(MYDEBUG) MESSAGE("AddHypothesisToShape")
761 if (theStudy->_is_nil() || theMesh->_is_nil() ||
762 theHyp->_is_nil() || theShape->_is_nil() )
765 SALOMEDS::SObject_var aMeshSO = ObjectToSObject( theStudy, theMesh );
766 if ( aMeshSO->_is_nil() )
767 aMeshSO = PublishMesh( theStudy, theMesh );
768 SALOMEDS::SObject_var aHypSO = PublishHypothesis( theStudy, theHyp );
769 if ( aMeshSO->_is_nil() || aHypSO->_is_nil())
772 // Find a mesh or submesh refering to theShape
773 SALOMEDS::SObject_var aMeshOrSubMesh =
774 GetMeshOrSubmeshByShape( theStudy, theMesh, theShape );
775 if ( aMeshOrSubMesh->_is_nil() )
778 //Find or Create Applied Hypothesis root
779 bool aIsAlgo = !SMESH::SMESH_Algo::_narrow( theHyp )->_is_nil();
780 SALOMEDS::SObject_var AHR =
781 publish (theStudy, CORBA::Object::_nil(), aMeshOrSubMesh,
782 aIsAlgo ? GetRefOnAppliedAlgorithmsTag() : GetRefOnAppliedHypothesisTag(),
783 aIsAlgo ? "ICON_SMESH_TREE_ALGO" : "ICON_SMESH_TREE_HYPO", false);
784 SetName( AHR, aIsAlgo ? "Applied algorithms" : "Applied hypotheses" );
785 if ( AHR->_is_nil() )
788 addReference( theStudy, AHR, theHyp );
789 if(MYDEBUG) MESSAGE("AddHypothesisToShape--END")
793 //=======================================================================
794 //function : RemoveHypothesisFromShape
796 //=======================================================================
798 bool SMESH_Gen_i::RemoveHypothesisFromShape(SALOMEDS::Study_ptr theStudy,
799 SMESH::SMESH_Mesh_ptr theMesh,
800 GEOM::GEOM_Object_ptr theShape,
801 SMESH::SMESH_Hypothesis_ptr theHyp)
803 if (theStudy->_is_nil() || theMesh->_is_nil() ||
804 theHyp->_is_nil() || theShape->_is_nil() )
807 SALOMEDS::SObject_var aHypSO = ObjectToSObject( theStudy, theHyp );
808 if ( aHypSO->_is_nil() )
811 // Find a mesh or submesh refering to theShape
812 SALOMEDS::SObject_var aMeshOrSubMesh =
813 GetMeshOrSubmeshByShape( theStudy, theMesh, theShape );
814 if ( aMeshOrSubMesh->_is_nil() )
817 // Find and remove a reference to aHypSO
818 SALOMEDS::SObject_var aRef, anObj;
819 CORBA::String_var anID = CORBA::string_dup( aHypSO->GetID() );
820 SALOMEDS::ChildIterator_var it = theStudy->NewChildIterator( aMeshOrSubMesh );
821 for ( it->InitEx( true ); it->More(); it->Next() ) {
823 if (anObj->ReferencedObject( aRef ) && strcmp( aRef->GetID(), anID ) == 0 ) {
824 theStudy->NewBuilder()->RemoveObject( anObj );