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 ))
184 aSO = theStudy->FindObjectIOR( SMESH_Gen_i::GetORB()->object_to_string( theObject ) );
188 //=======================================================================
189 //function : objectToServant
191 //=======================================================================
193 template<typename T> static inline T* objectToServant( CORBA::Object_ptr theIOR )
195 return dynamic_cast<T*>( SMESH_Gen_i::GetServant( theIOR ).in() );
198 //=======================================================================
199 //function : ShapeToGeomObject
201 //=======================================================================
203 GEOM::GEOM_Object_ptr SMESH_Gen_i::ShapeToGeomObject (const TopoDS_Shape& theShape )
205 GEOM::GEOM_Object_var aShapeObj;
206 if ( !theShape.IsNull() ) {
207 GEOM_Client* aClient = GetShapeReader();
208 TCollection_AsciiString IOR;
209 if ( aClient && aClient->Find( theShape, IOR ))
210 aShapeObj = GEOM::GEOM_Object::_narrow
211 ( GetORB()->string_to_object( IOR.ToCString() ) );
213 return aShapeObj._retn();
216 //=======================================================================
217 //function : GeomObjectToShape
219 //=======================================================================
221 TopoDS_Shape SMESH_Gen_i::GeomObjectToShape(GEOM::GEOM_Object_ptr theGeomObject)
224 if ( !theGeomObject->_is_nil() ) {
225 GEOM_Client* aClient = GetShapeReader();
226 GEOM::GEOM_Gen_ptr aGeomEngine = GetGeomEngine();
227 if ( aClient && !aGeomEngine->_is_nil () )
228 S = aClient->GetShape( aGeomEngine, theGeomObject );
233 //=======================================================================
236 //=======================================================================
238 static SALOMEDS::SObject_ptr publish(SALOMEDS::Study_ptr theStudy,
239 CORBA::Object_ptr theIOR,
240 SALOMEDS::SObject_ptr theFatherObject,
241 const int theTag = 0,
242 const char* thePixMap = 0,
243 const bool theSelectable = true)
245 SALOMEDS::SObject_var SO = SMESH_Gen_i::ObjectToSObject( theStudy, theIOR );
246 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
247 if ( SO->_is_nil() ) {
249 SO = aStudyBuilder->NewObject( theFatherObject );
250 else if ( !theFatherObject->FindSubObject( theTag, SO ))
251 SO = aStudyBuilder->NewObjectToTag( theFatherObject, theTag );
254 SALOMEDS::GenericAttribute_var anAttr;
255 if ( !CORBA::is_nil( theIOR )) {
256 anAttr = aStudyBuilder->FindOrCreateAttribute( SO, "AttributeIOR" );
257 SALOMEDS::AttributeIOR::_narrow(anAttr)->SetValue
258 ( SMESH_Gen_i::GetORB()->object_to_string( theIOR ) );
261 anAttr = aStudyBuilder->FindOrCreateAttribute( SO, "AttributePixMap" );
262 SALOMEDS::AttributePixMap::_narrow( anAttr )->SetPixMap( thePixMap );
264 if ( !theSelectable ) {
265 anAttr = aStudyBuilder->FindOrCreateAttribute( SO, "AttributeSelectable" );
266 SALOMEDS::AttributeSelectable::_narrow( anAttr )->SetSelectable( false );
271 //=======================================================================
274 //=======================================================================
276 void SMESH_Gen_i::SetName(SALOMEDS::SObject_ptr theSObject,
278 const char* theDefaultName)
280 if ( !theSObject->_is_nil() ) {
281 SALOMEDS::StudyBuilder_var aStudyBuilder = theSObject->GetStudy()->NewBuilder();
282 SALOMEDS::GenericAttribute_var anAttr =
283 aStudyBuilder->FindOrCreateAttribute( theSObject, "AttributeName" );
284 SALOMEDS::AttributeName_var aNameAttr = SALOMEDS::AttributeName::_narrow( anAttr );
285 if ( theName && strlen( theName ) != 0 )
286 aNameAttr->SetValue( theName );
288 CORBA::String_var curName = CORBA::string_dup( aNameAttr->Value() );
289 if ( strlen( curName ) == 0 ) {
290 TCollection_AsciiString aName( (char*) theDefaultName );
291 aName += TCollection_AsciiString("_") + TCollection_AsciiString( theSObject->Tag() );
292 aNameAttr->SetValue( aName.ToCString() );
298 //=======================================================================
299 //function : addReference
301 //=======================================================================
303 static void addReference (SALOMEDS::Study_ptr theStudy,
304 SALOMEDS::SObject_ptr theSObject,
305 CORBA::Object_ptr theToObject,
308 SALOMEDS::SObject_var aToObjSO = SMESH_Gen_i::ObjectToSObject( theStudy, theToObject );
309 if ( !aToObjSO->_is_nil() && !theSObject->_is_nil() ) {
310 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
311 SALOMEDS::SObject_var aReferenceSO;
313 // check if the reference to theToObject already exists
314 // and find a free label for the reference object
315 bool isReferred = false;
317 SALOMEDS::ChildIterator_var anIter = theStudy->NewChildIterator( theSObject );
318 for ( ; !isReferred && anIter->More(); anIter->Next(), ++tag ) {
319 if ( anIter->Value()->ReferencedObject( aReferenceSO )) {
320 if ( strcmp( aReferenceSO->GetID(), aToObjSO->GetID() ) == 0 )
323 else if ( !theTag ) {
324 SALOMEDS::GenericAttribute_var anAttr;
325 if ( !anIter->Value()->FindAttribute( anAttr, "AttributeIOR" ))
334 if ( !theSObject->FindSubObject( theTag, aReferenceSO ))
335 aReferenceSO = aStudyBuilder->NewObjectToTag( theSObject, theTag );
336 aStudyBuilder->Addreference( aReferenceSO, aToObjSO );
340 //=============================================================================
342 * SMESH_Gen_i::PublishInStudy
344 * Publish object in the study
346 //=============================================================================
348 SALOMEDS::SObject_ptr SMESH_Gen_i::PublishInStudy(SALOMEDS::Study_ptr theStudy,
349 SALOMEDS::SObject_ptr theSObject,
350 CORBA::Object_ptr theIOR,
352 throw (SALOME::SALOME_Exception)
354 Unexpect aCatch(SALOME_SalomeException);
355 SALOMEDS::SObject_var aSO;
356 if ( CORBA::is_nil( theStudy ) || CORBA::is_nil( theIOR ))
358 if(MYDEBUG) MESSAGE("PublishInStudy");
361 SMESH::SMESH_Mesh_var aMesh = SMESH::SMESH_Mesh::_narrow( theIOR );
362 if( !aMesh->_is_nil() )
363 aSO = PublishMesh( theStudy, aMesh, theName );
365 // Publishing a sub-mesh
366 SMESH::SMESH_subMesh_var aSubMesh = SMESH::SMESH_subMesh::_narrow( theIOR );
367 if( aSO->_is_nil() && !aSubMesh->_is_nil() ) {
368 GEOM::GEOM_Object_var aShapeObject = aSubMesh->GetSubShape();
369 aMesh = aSubMesh->GetFather();
370 aSO = PublishSubMesh( theStudy, aMesh, aSubMesh, aShapeObject, theName );
373 // Publishing a hypothesis or algorithm
374 SMESH::SMESH_Hypothesis_var aHyp = SMESH::SMESH_Hypothesis::_narrow( theIOR );
375 if ( aSO->_is_nil() && !aHyp->_is_nil() )
376 aSO = PublishHypothesis( theStudy, aHyp );
378 // Publishing a group
379 SMESH::SMESH_GroupBase_var aGroup = SMESH::SMESH_GroupBase::_narrow(theIOR);
380 if ( aSO->_is_nil() && !aGroup->_is_nil() ) {
381 GEOM::GEOM_Object_var aShapeObject;
382 aMesh = aGroup->GetMesh();
383 aSO = PublishGroup( theStudy, aMesh, aGroup, aShapeObject, theName );
385 if(MYDEBUG) MESSAGE("PublishInStudy_END");
390 //=======================================================================
391 //function : PublishComponent
393 //=======================================================================
395 SALOMEDS::SComponent_ptr SMESH_Gen_i::PublishComponent(SALOMEDS::Study_ptr theStudy)
397 if ( CORBA::is_nil( theStudy ))
398 return SALOMEDS::SComponent::_nil();
399 if(MYDEBUG) MESSAGE("PublishComponent");
401 SALOMEDS::SComponent_var father =
402 SALOMEDS::SComponent::_narrow( theStudy->FindComponent( ComponentDataType() ) );
403 if ( !CORBA::is_nil( father ) )
404 return father._retn();
406 SALOME_ModuleCatalog::ModuleCatalog_var aCat =
407 SALOME_ModuleCatalog::ModuleCatalog::_narrow( GetNS()->Resolve("/Kernel/ModulCatalog") );
408 if ( CORBA::is_nil( aCat ) )
409 return father._retn();
411 SALOME_ModuleCatalog::Acomponent_var aComp = aCat->GetComponent( ComponentDataType() );
412 if ( CORBA::is_nil( aComp ) )
413 return father._retn();
415 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
416 SALOMEDS::GenericAttribute_var anAttr;
417 SALOMEDS::AttributePixMap_var aPixmap;
419 father = aStudyBuilder->NewComponent( ComponentDataType() );
420 aStudyBuilder->DefineComponentInstance( father, SMESH_Gen::_this() );
421 anAttr = aStudyBuilder->FindOrCreateAttribute( father, "AttributePixMap" );
422 aPixmap = SALOMEDS::AttributePixMap::_narrow( anAttr );
423 aPixmap ->SetPixMap( "ICON_OBJBROWSER_SMESH" );
424 SetName( father, aComp->componentusername(), "MESH" );
425 if(MYDEBUG) MESSAGE("PublishComponent--END");
427 return father._retn();
430 //=============================================================================
432 * findMaxChildTag [ static internal ]
434 * Finds maximum child tag for the given object
436 //=============================================================================
438 static long findMaxChildTag( SALOMEDS::SObject_ptr theSObject )
441 if ( !theSObject->_is_nil() ) {
442 SALOMEDS::Study_var aStudy = theSObject->GetStudy();
443 if ( !aStudy->_is_nil() ) {
444 SALOMEDS::ChildIterator_var anIter = aStudy->NewChildIterator( theSObject );
445 for ( ; anIter->More(); anIter->Next() ) {
446 long nTag = anIter->Value()->Tag();
455 //=======================================================================
456 //function : PublishMesh
458 //=======================================================================
460 SALOMEDS::SObject_ptr SMESH_Gen_i::PublishMesh (SALOMEDS::Study_ptr theStudy,
461 SMESH::SMESH_Mesh_ptr theMesh,
464 if ( CORBA::is_nil( theStudy ) ||
465 CORBA::is_nil( theMesh ))
466 return SALOMEDS::SComponent::_nil();
467 if(MYDEBUG) MESSAGE("PublishMesh--IN");
469 // find or publish a mesh
471 SALOMEDS::SObject_var aMeshSO = ObjectToSObject( theStudy, theMesh );
472 if ( aMeshSO->_is_nil() )
474 SALOMEDS::SComponent_var father = PublishComponent( theStudy );
475 if ( father->_is_nil() )
476 return aMeshSO._retn();
478 // Find correct free tag
479 long aTag = findMaxChildTag( father.in() );
480 if ( aTag <= GetAlgorithmsRootTag() )
481 aTag = GetAlgorithmsRootTag() + 1;
485 aMeshSO = publish (theStudy, theMesh, father, aTag, "ICON_SMESH_TREE_MESH_WARN" );
486 if ( aMeshSO->_is_nil() )
487 return aMeshSO._retn();
489 SetName( aMeshSO, theName, "Mesh" );
491 // Add shape reference
493 GEOM::GEOM_Object_var aShapeObject = theMesh->GetShapeToMesh();
494 if ( !CORBA::is_nil( aShapeObject )) {
495 addReference( theStudy, aMeshSO, aShapeObject, GetRefOnShapeTag() );
497 // Publish global hypotheses
499 SMESH::ListOfHypothesis * hypList = theMesh->GetHypothesisList( aShapeObject );
501 for ( int i = 0; i < hypList->length(); i++ ) {
502 SMESH::SMESH_Hypothesis_var aHyp = SMESH::SMESH_Hypothesis::_narrow( (*hypList)[ i ]);
503 PublishHypothesis( theStudy, aHyp );
504 AddHypothesisToShape( theStudy, theMesh, aShapeObject, aHyp );
510 SMESH_Mesh_i* mesh_i = objectToServant<SMESH_Mesh_i>( theMesh );
512 return aMeshSO._retn();
513 map<int, SMESH_subMesh_i*>& subMap = mesh_i->_mapSubMesh_i;
514 map<int, SMESH_subMesh_i*>::iterator subIt = subMap.begin();
515 for ( ; subIt != subMap.end(); subIt++ ) {
516 SMESH::SMESH_subMesh_ptr aSubMesh = (*subIt).second->_this();
517 if ( !CORBA::is_nil( aSubMesh )) {
518 aShapeObject = aSubMesh->GetSubShape();
519 PublishSubMesh( theStudy, theMesh, aSubMesh, aShapeObject );
524 const map<int, SMESH::SMESH_GroupBase_ptr>& grMap = mesh_i->getGroups();
525 map<int, SMESH::SMESH_GroupBase_ptr>::const_iterator it = grMap.begin();
526 for ( ; it != grMap.end(); it++ )
528 SMESH::SMESH_GroupBase_ptr aGroup = (*it).second;
529 if ( !aGroup->_is_nil() ) {
530 GEOM::GEOM_Object_var aShapeObj;
531 SMESH::SMESH_GroupOnGeom_var aGeomGroup =
532 SMESH::SMESH_GroupOnGeom::_narrow( aGroup );
533 if ( !aGeomGroup->_is_nil() )
534 aShapeObj = aGeomGroup->GetShape();
535 PublishGroup( theStudy, theMesh, aGroup, aShapeObj );
539 if(MYDEBUG) MESSAGE("PublishMesh_END");
540 return aMeshSO._retn();
543 //=======================================================================
544 //function : PublishSubMesh
546 //=======================================================================
548 SALOMEDS::SObject_ptr SMESH_Gen_i::PublishSubMesh (SALOMEDS::Study_ptr theStudy,
549 SMESH::SMESH_Mesh_ptr theMesh,
550 SMESH::SMESH_subMesh_ptr theSubMesh,
551 GEOM::GEOM_Object_ptr theShapeObject,
554 if (theStudy->_is_nil() || theMesh->_is_nil() ||
555 theSubMesh->_is_nil() || theShapeObject->_is_nil() )
556 return SALOMEDS::SObject::_nil();
558 SALOMEDS::SObject_var aSubMeshSO = ObjectToSObject( theStudy, theSubMesh );
559 if ( aSubMeshSO->_is_nil() )
561 SALOMEDS::SObject_var aMeshSO = ObjectToSObject( theStudy, theMesh );
562 if ( aMeshSO->_is_nil() ) {
563 aMeshSO = PublishMesh( theStudy, theMesh );
564 if ( aMeshSO->_is_nil())
565 return SALOMEDS::SObject::_nil();
567 // Find submesh sub-tree tag
569 char* aRootName = "";
570 switch ( theShapeObject->GetShapeType() ) {
572 aRootTag = GetSubMeshOnVertexTag();
573 aRootName = "SubMeshes on Vertex";
576 aRootTag = GetSubMeshOnEdgeTag();
577 aRootName = "SubMeshes on Edge";
580 aRootTag = GetSubMeshOnWireTag();
581 aRootName = "SubMeshes on Wire";
584 aRootTag = GetSubMeshOnFaceTag();
585 aRootName = "SubMeshes on Face";
588 aRootTag = GetSubMeshOnShellTag();
589 aRootName = "SubMeshes on Shell";
592 aRootTag = GetSubMeshOnSolidTag();
593 aRootName = "SubMeshes on Solid";
596 aRootTag = GetSubMeshOnCompoundTag();
597 aRootName = "SubMeshes on Compound";
601 // Find or create submesh root
602 SALOMEDS::SObject_var aRootSO = publish (theStudy, CORBA::Object::_nil(),
603 aMeshSO, aRootTag, 0, false );
604 SetName( aRootSO, aRootName );
606 // Add new submesh to corresponding sub-tree
607 aSubMeshSO = publish (theStudy, theSubMesh, aRootSO, 0, "ICON_SMESH_TREE_MESH_WARN");
608 if ( aSubMeshSO->_is_nil() )
609 return aSubMeshSO._retn();
611 SetName( aSubMeshSO, theName, "SubMesh" );
613 // Add reference to theShapeObject
615 addReference( theStudy, aSubMeshSO, theShapeObject, 1 );
617 // Publish hypothesis
619 SMESH::ListOfHypothesis * hypList = theMesh->GetHypothesisList( theShapeObject );
621 for ( int i = 0; i < hypList->length(); i++ ) {
622 SMESH::SMESH_Hypothesis_var aHyp = SMESH::SMESH_Hypothesis::_narrow( (*hypList)[ i ]);
623 PublishHypothesis( theStudy, aHyp );
624 AddHypothesisToShape( theStudy, theMesh, theShapeObject, aHyp );
627 return aSubMeshSO._retn();
630 //=======================================================================
631 //function : PublishGroup
633 //=======================================================================
635 SALOMEDS::SObject_ptr SMESH_Gen_i::PublishGroup (SALOMEDS::Study_ptr theStudy,
636 SMESH::SMESH_Mesh_ptr theMesh,
637 SMESH::SMESH_GroupBase_ptr theGroup,
638 GEOM::GEOM_Object_ptr theShapeObject,
641 if (theStudy->_is_nil() || theMesh->_is_nil() || theGroup->_is_nil() )
642 return SALOMEDS::SObject::_nil();
644 SALOMEDS::SObject_var aGroupSO = ObjectToSObject( theStudy, theGroup );
645 if ( aGroupSO->_is_nil() )
647 SALOMEDS::SObject_var aMeshSO = ObjectToSObject( theStudy, theMesh );
648 if ( aMeshSO->_is_nil() ) {
649 aMeshSO = PublishInStudy( theStudy, SALOMEDS::SObject::_nil(), theMesh, "");
650 if ( aMeshSO->_is_nil())
651 return SALOMEDS::SObject::_nil();
653 int aType = (int)theGroup->GetType();
654 const char* aRootNames[] = {
655 "Compound Groups", "Groups of Nodes",
656 "Groups of Edges", "Groups of Faces", "Groups of Volumes" };
658 // Currently, groups with heterogenous content are not supported
659 if ( aType != SMESH::ALL ) {
660 long aRootTag = GetNodeGroupsTag() + aType - 1;
662 // Find or create groups root
663 SALOMEDS::SObject_var aRootSO = publish (theStudy, CORBA::Object::_nil(),
664 aMeshSO, aRootTag, 0, false );
666 SetName( aRootSO, aRootNames[aType] );
668 // Add new group to corresponding sub-tree
669 aGroupSO = publish (theStudy, theGroup, aRootSO, 0, "ICON_SMESH_TREE_GROUP" );
671 if ( aGroupSO->_is_nil() )
672 return aGroupSO._retn();
675 SetName( aGroupSO, theName, "Group" );
677 //Add reference to geometry
678 if ( !theShapeObject->_is_nil() )
679 addReference( theStudy, aGroupSO, theShapeObject, 1 );
681 return aGroupSO._retn();
684 //=======================================================================
685 //function : PublishHypothesis
687 //=======================================================================
689 SALOMEDS::SObject_ptr
690 SMESH_Gen_i::PublishHypothesis (SALOMEDS::Study_ptr theStudy,
691 SMESH::SMESH_Hypothesis_ptr theHyp,
694 if(MYDEBUG) MESSAGE("PublishHypothesis")
695 if (theStudy->_is_nil() || theHyp->_is_nil())
696 return SALOMEDS::SObject::_nil();
698 SALOMEDS::SObject_var aHypSO = ObjectToSObject( theStudy, theHyp );
699 if ( aHypSO->_is_nil() )
701 SALOMEDS::SComponent_var father = PublishComponent( theStudy );
702 if ( father->_is_nil() )
703 return aHypSO._retn();
705 //Find or Create Hypothesis root
706 bool isAlgo = ( !SMESH::SMESH_Algo::_narrow( theHyp )->_is_nil() );
707 int aRootTag = isAlgo ? GetAlgorithmsRootTag() : GetHypothesisRootTag();
708 SALOMEDS::SObject_var aRootSO =
709 publish (theStudy, CORBA::Object::_nil(),father, aRootTag,
710 isAlgo ? "ICON_SMESH_TREE_ALGO" : "ICON_SMESH_TREE_HYPO", false);
711 SetName( aRootSO, isAlgo ? "Algorithms" : "Hypotheses" );
713 // Add New Hypothesis
714 string aPmName = isAlgo ? "ICON_SMESH_TREE_ALGO_" : "ICON_SMESH_TREE_HYPO_";
715 aPmName += theHyp->GetName();
716 aHypSO = publish( theStudy, theHyp, aRootSO, 0, aPmName.c_str() );
719 if ( !aHypSO->_is_nil() ) {
720 CORBA::String_var aHypName = CORBA::string_dup( theHyp->GetName() );
721 SetName( aHypSO, theName, aHypName );
724 if(MYDEBUG) MESSAGE("PublishHypothesis--END")
725 return aHypSO._retn();
728 //=======================================================================
729 //function : GetMeshOrSubmeshByShape
731 //=======================================================================
733 SALOMEDS::SObject_ptr
734 SMESH_Gen_i::GetMeshOrSubmeshByShape (SALOMEDS::Study_ptr theStudy,
735 SMESH::SMESH_Mesh_ptr theMesh,
736 GEOM::GEOM_Object_ptr theShape)
738 if(MYDEBUG) MESSAGE("GetMeshOrSubmeshByShape")
739 SALOMEDS::SObject_var aMeshOrSubMesh;
740 if ( theShape->_is_nil() || theMesh->_is_nil() )
741 return aMeshOrSubMesh._retn();
743 TopoDS_Shape aShape = GeomObjectToShape( theShape );
744 SMESH_Mesh_i* mesh_i = objectToServant<SMESH_Mesh_i>( theMesh );
746 if ( !aShape.IsNull() && mesh_i && mesh_i->GetImpl().GetMeshDS() ) {
747 SMESHDS_Mesh* meshDS = mesh_i->GetImpl().GetMeshDS();
748 if ( aShape.IsSame( meshDS->ShapeToMesh() ))
749 aMeshOrSubMesh = ObjectToSObject( theStudy, theMesh );
751 int shapeID = meshDS->ShapeToIndex( aShape );
752 SMESH::SMESH_subMesh_var aSubMesh = mesh_i->getSubMesh(shapeID);
753 if ( !aSubMesh->_is_nil() )
754 aMeshOrSubMesh = ObjectToSObject( theStudy, aSubMesh );
757 if(MYDEBUG) MESSAGE("GetMeshOrSubmeshByShape--END")
758 return aMeshOrSubMesh._retn();
761 //=======================================================================
762 //function : AddHypothesisToShape
764 //=======================================================================
766 bool SMESH_Gen_i::AddHypothesisToShape(SALOMEDS::Study_ptr theStudy,
767 SMESH::SMESH_Mesh_ptr theMesh,
768 GEOM::GEOM_Object_ptr theShape,
769 SMESH::SMESH_Hypothesis_ptr theHyp)
771 if(MYDEBUG) MESSAGE("AddHypothesisToShape")
772 if (theStudy->_is_nil() || theMesh->_is_nil() ||
773 theHyp->_is_nil() || theShape->_is_nil() )
776 SALOMEDS::SObject_var aMeshSO = ObjectToSObject( theStudy, theMesh );
777 if ( aMeshSO->_is_nil() )
778 aMeshSO = PublishMesh( theStudy, theMesh );
779 SALOMEDS::SObject_var aHypSO = PublishHypothesis( theStudy, theHyp );
780 if ( aMeshSO->_is_nil() || aHypSO->_is_nil())
783 // Find a mesh or submesh refering to theShape
784 SALOMEDS::SObject_var aMeshOrSubMesh =
785 GetMeshOrSubmeshByShape( theStudy, theMesh, theShape );
786 if ( aMeshOrSubMesh->_is_nil() )
789 TopoDS_Shape aShape = GeomObjectToShape( theShape );
790 SMESH_Mesh_i* mesh_i = objectToServant<SMESH_Mesh_i>( theMesh );
791 if ( !aShape.IsNull() && mesh_i && mesh_i->GetImpl().GetMeshDS() ) {
792 SMESHDS_Mesh* meshDS = mesh_i->GetImpl().GetMeshDS();
793 int shapeID = meshDS->ShapeToIndex( aShape );
794 SMESH::SMESH_subMesh_var aSubMesh = mesh_i->getSubMesh(shapeID);
795 aMeshOrSubMesh = PublishSubMesh( theStudy, theMesh, aSubMesh, theShape );
797 if ( aMeshOrSubMesh->_is_nil() )
801 //Find or Create Applied Hypothesis root
802 bool aIsAlgo = !SMESH::SMESH_Algo::_narrow( theHyp )->_is_nil();
803 SALOMEDS::SObject_var AHR =
804 publish (theStudy, CORBA::Object::_nil(), aMeshOrSubMesh,
805 aIsAlgo ? GetRefOnAppliedAlgorithmsTag() : GetRefOnAppliedHypothesisTag(),
806 aIsAlgo ? "ICON_SMESH_TREE_ALGO" : "ICON_SMESH_TREE_HYPO", false);
807 SetName( AHR, aIsAlgo ? "Applied algorithms" : "Applied hypotheses" );
808 if ( AHR->_is_nil() )
811 addReference( theStudy, AHR, theHyp );
812 if(MYDEBUG) MESSAGE("AddHypothesisToShape--END")
816 //=======================================================================
817 //function : RemoveHypothesisFromShape
819 //=======================================================================
821 bool SMESH_Gen_i::RemoveHypothesisFromShape(SALOMEDS::Study_ptr theStudy,
822 SMESH::SMESH_Mesh_ptr theMesh,
823 GEOM::GEOM_Object_ptr theShape,
824 SMESH::SMESH_Hypothesis_ptr theHyp)
826 if (theStudy->_is_nil() || theMesh->_is_nil() ||
827 theHyp->_is_nil() || theShape->_is_nil() )
830 SALOMEDS::SObject_var aHypSO = ObjectToSObject( theStudy, theHyp );
831 if ( aHypSO->_is_nil() )
834 // Find a mesh or submesh refering to theShape
835 SALOMEDS::SObject_var aMeshOrSubMesh =
836 GetMeshOrSubmeshByShape( theStudy, theMesh, theShape );
837 if ( aMeshOrSubMesh->_is_nil() )
840 // Find and remove a reference to aHypSO
841 SALOMEDS::SObject_var aRef, anObj;
842 CORBA::String_var anID = CORBA::string_dup( aHypSO->GetID() );
843 SALOMEDS::ChildIterator_var it = theStudy->NewChildIterator( aMeshOrSubMesh );
844 for ( it->InitEx( true ); it->More(); it->Next() ) {
846 if (anObj->ReferencedObject( aRef ) && strcmp( aRef->GetID(), anID ) == 0 ) {
847 theStudy->NewBuilder()->RemoveObject( anObj );