1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 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
22 // SMESH SMESH_I : idl implementation based on 'SMESH' unit's calsses
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;
46 static int VARIABLE_DEBUG = 0;
48 static int MYDEBUG = 0;
49 static int VARIABLE_DEBUG = 0;
52 //=============================================================================
54 * Get...Tag [ static ]
56 * Methods which determine SMESH data model structure
58 //=============================================================================
60 long SMESH_Gen_i::GetHypothesisRootTag()
62 return SMESH::Tag_HypothesisRoot;
65 long SMESH_Gen_i::GetAlgorithmsRootTag()
67 return SMESH::Tag_AlgorithmsRoot;
70 long SMESH_Gen_i::GetRefOnShapeTag()
72 return SMESH::Tag_RefOnShape;
75 long SMESH_Gen_i::GetRefOnAppliedHypothesisTag()
77 return SMESH::Tag_RefOnAppliedHypothesis;
80 long SMESH_Gen_i::GetRefOnAppliedAlgorithmsTag()
82 return SMESH::Tag_RefOnAppliedAlgorithms;
85 long SMESH_Gen_i::GetSubMeshOnVertexTag()
87 return SMESH::Tag_SubMeshOnVertex;
90 long SMESH_Gen_i::GetSubMeshOnEdgeTag()
92 return SMESH::Tag_SubMeshOnEdge;
95 long SMESH_Gen_i::GetSubMeshOnFaceTag()
97 return SMESH::Tag_SubMeshOnFace;
100 long SMESH_Gen_i::GetSubMeshOnSolidTag()
102 return SMESH::Tag_SubMeshOnSolid;
105 long SMESH_Gen_i::GetSubMeshOnCompoundTag()
107 return SMESH::Tag_SubMeshOnCompound;
110 long SMESH_Gen_i::GetSubMeshOnWireTag()
112 return SMESH::Tag_SubMeshOnWire;
115 long SMESH_Gen_i::GetSubMeshOnShellTag()
117 return SMESH::Tag_SubMeshOnShell;
120 long SMESH_Gen_i::GetNodeGroupsTag()
122 return SMESH::Tag_NodeGroups;
125 long SMESH_Gen_i::GetEdgeGroupsTag()
127 return SMESH::Tag_EdgeGroups;
130 long SMESH_Gen_i::GetFaceGroupsTag()
132 return SMESH::Tag_FaceGroups;
135 long SMESH_Gen_i::GetVolumeGroupsTag()
137 return SMESH::Tag_VolumeGroups;
140 //=============================================================================
142 * SMESH_Gen_i::CanPublishInStudy
144 * Returns true if object can be published in the study
146 //=============================================================================
148 bool SMESH_Gen_i::CanPublishInStudy(CORBA::Object_ptr theIOR)
150 if(MYDEBUG) MESSAGE("CanPublishInStudy - "<<!CORBA::is_nil(myCurrentStudy));
151 if(CORBA::is_nil(myCurrentStudy))
154 SMESH::SMESH_Mesh_var aMesh = SMESH::SMESH_Mesh::_narrow(theIOR);
155 if( !aMesh->_is_nil() )
158 SMESH::SMESH_subMesh_var aSubMesh = SMESH::SMESH_subMesh::_narrow(theIOR);
159 if( !aSubMesh->_is_nil() )
162 SMESH::SMESH_Hypothesis_var aHyp = SMESH::SMESH_Hypothesis::_narrow(theIOR);
163 if( !aHyp->_is_nil() )
166 SMESH::SMESH_GroupBase_var aGroup = SMESH::SMESH_GroupBase::_narrow(theIOR);
167 if( !aGroup->_is_nil() )
170 if(MYDEBUG) MESSAGE("CanPublishInStudy--CANT");
174 //=======================================================================
175 //function : ObjectToSObject
177 //=======================================================================
179 SALOMEDS::SObject_ptr SMESH_Gen_i::ObjectToSObject(SALOMEDS::Study_ptr theStudy,
180 CORBA::Object_ptr theObject)
182 SALOMEDS::SObject_var aSO;
183 if ( !CORBA::is_nil( theStudy ) && !CORBA::is_nil( theObject ))
185 CORBA::String_var objStr = SMESH_Gen_i::GetORB()->object_to_string( theObject );
186 aSO = theStudy->FindObjectIOR( objStr.in() );
191 //=======================================================================
192 //function : objectToServant
194 //=======================================================================
196 template<typename T> static inline T* objectToServant( CORBA::Object_ptr theIOR )
198 return dynamic_cast<T*>( SMESH_Gen_i::GetServant( theIOR ).in() );
201 //=======================================================================
202 //function : ShapeToGeomObject
204 //=======================================================================
206 GEOM::GEOM_Object_ptr SMESH_Gen_i::ShapeToGeomObject (const TopoDS_Shape& theShape )
208 GEOM::GEOM_Object_var aShapeObj;
209 if ( !theShape.IsNull() ) {
210 GEOM_Client* aClient = GetShapeReader();
211 TCollection_AsciiString IOR;
212 if ( aClient && aClient->Find( theShape, IOR ))
214 CORBA::Object_var obj = GetORB()->string_to_object( IOR.ToCString() );
215 aShapeObj = GEOM::GEOM_Object::_narrow ( obj );
218 return aShapeObj._retn();
221 //=======================================================================
222 //function : GeomObjectToShape
224 //=======================================================================
226 TopoDS_Shape SMESH_Gen_i::GeomObjectToShape(GEOM::GEOM_Object_ptr theGeomObject)
229 if ( !theGeomObject->_is_nil() ) {
230 GEOM_Client* aClient = GetShapeReader();
231 GEOM::GEOM_Gen_ptr aGeomEngine = GetGeomEngine();
232 if ( aClient && !aGeomEngine->_is_nil () )
233 S = aClient->GetShape( aGeomEngine, theGeomObject );
238 //=======================================================================
241 //=======================================================================
243 static SALOMEDS::SObject_ptr publish(SALOMEDS::Study_ptr theStudy,
244 CORBA::Object_ptr theIOR,
245 SALOMEDS::SObject_ptr theFatherObject,
246 const int theTag = 0,
247 const char* thePixMap = 0,
248 const bool theSelectable = true)
250 SALOMEDS::SObject_var SO = SMESH_Gen_i::ObjectToSObject( theStudy, theIOR );
251 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
252 if ( SO->_is_nil() ) {
254 SO = aStudyBuilder->NewObject( theFatherObject );
255 else if ( !theFatherObject->FindSubObject( theTag, SO ))
256 SO = aStudyBuilder->NewObjectToTag( theFatherObject, theTag );
259 SALOMEDS::GenericAttribute_var anAttr;
260 if ( !CORBA::is_nil( theIOR )) {
261 anAttr = aStudyBuilder->FindOrCreateAttribute( SO, "AttributeIOR" );
262 CORBA::String_var objStr = SMESH_Gen_i::GetORB()->object_to_string( theIOR );
263 SALOMEDS::AttributeIOR::_narrow(anAttr)->SetValue( objStr.in() );
266 anAttr = aStudyBuilder->FindOrCreateAttribute( SO, "AttributePixMap" );
267 SALOMEDS::AttributePixMap_var pm = SALOMEDS::AttributePixMap::_narrow( anAttr );
268 pm->SetPixMap( thePixMap );
270 if ( !theSelectable ) {
271 anAttr = aStudyBuilder->FindOrCreateAttribute( SO, "AttributeSelectable" );
272 SALOMEDS::AttributeSelectable::_narrow( anAttr )->SetSelectable( false );
277 //=======================================================================
280 //=======================================================================
282 void SMESH_Gen_i::SetName(SALOMEDS::SObject_ptr theSObject,
284 const char* theDefaultName)
286 if ( !theSObject->_is_nil() ) {
287 SALOMEDS::StudyBuilder_var aStudyBuilder = theSObject->GetStudy()->NewBuilder();
288 SALOMEDS::GenericAttribute_var anAttr =
289 aStudyBuilder->FindOrCreateAttribute( theSObject, "AttributeName" );
290 SALOMEDS::AttributeName_var aNameAttr = SALOMEDS::AttributeName::_narrow( anAttr );
291 if ( theName && strlen( theName ) != 0 )
292 aNameAttr->SetValue( theName );
294 CORBA::String_var curName = CORBA::string_dup( aNameAttr->Value() );
295 if ( strlen( curName ) == 0 ) {
296 TCollection_AsciiString aName( (char*) theDefaultName );
297 aName += TCollection_AsciiString("_") + TCollection_AsciiString( theSObject->Tag() );
298 aNameAttr->SetValue( aName.ToCString() );
304 //=======================================================================
305 //function : SetPixMap
307 //=======================================================================
309 void SMESH_Gen_i::SetPixMap(SALOMEDS::SObject_ptr theSObject,
310 const char* thePixMap)
312 if ( !theSObject->_is_nil() && thePixMap && strlen( thePixMap ))
314 SALOMEDS::Study_var aStudy = theSObject->GetStudy();
315 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
316 SALOMEDS::GenericAttribute_var anAttr =
317 aStudyBuilder->FindOrCreateAttribute( theSObject, "AttributePixMap" );
318 SALOMEDS::AttributePixMap_var aPMAttr = SALOMEDS::AttributePixMap::_narrow( anAttr );
319 aPMAttr->SetPixMap( thePixMap );
323 //=======================================================================
324 //function : addReference
326 //=======================================================================
328 static void addReference (SALOMEDS::Study_ptr theStudy,
329 SALOMEDS::SObject_ptr theSObject,
330 CORBA::Object_ptr theToObject,
333 SALOMEDS::SObject_var aToObjSO = SMESH_Gen_i::ObjectToSObject( theStudy, theToObject );
334 if ( !aToObjSO->_is_nil() && !theSObject->_is_nil() ) {
335 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
336 SALOMEDS::SObject_var aReferenceSO;
338 // check if the reference to theToObject already exists
339 // and find a free label for the reference object
340 bool isReferred = false;
342 SALOMEDS::ChildIterator_var anIter = theStudy->NewChildIterator( theSObject );
343 for ( ; !isReferred && anIter->More(); anIter->Next(), ++tag ) {
344 if ( anIter->Value()->ReferencedObject( aReferenceSO )) {
345 if ( strcmp( aReferenceSO->GetID(), aToObjSO->GetID() ) == 0 )
348 else if ( !theTag ) {
349 SALOMEDS::GenericAttribute_var anAttr;
350 if ( !anIter->Value()->FindAttribute( anAttr, "AttributeIOR" ))
359 if ( !theSObject->FindSubObject( theTag, aReferenceSO ))
360 aReferenceSO = aStudyBuilder->NewObjectToTag( theSObject, theTag );
361 aStudyBuilder->Addreference( aReferenceSO, aToObjSO );
365 //=============================================================================
367 * SMESH_Gen_i::PublishInStudy
369 * Publish object in the study
371 //=============================================================================
373 SALOMEDS::SObject_ptr SMESH_Gen_i::PublishInStudy(SALOMEDS::Study_ptr theStudy,
374 SALOMEDS::SObject_ptr theSObject,
375 CORBA::Object_ptr theIOR,
377 throw (SALOME::SALOME_Exception)
379 Unexpect aCatch(SALOME_SalomeException);
380 SALOMEDS::SObject_var aSO;
381 if ( CORBA::is_nil( theStudy ) || CORBA::is_nil( theIOR ))
383 if(MYDEBUG) MESSAGE("PublishInStudy");
386 SMESH::SMESH_Mesh_var aMesh = SMESH::SMESH_Mesh::_narrow( theIOR );
387 if( !aMesh->_is_nil() )
388 aSO = PublishMesh( theStudy, aMesh, theName );
390 // Publishing a sub-mesh
391 SMESH::SMESH_subMesh_var aSubMesh = SMESH::SMESH_subMesh::_narrow( theIOR );
392 if( aSO->_is_nil() && !aSubMesh->_is_nil() ) {
393 GEOM::GEOM_Object_var aShapeObject = aSubMesh->GetSubShape();
394 aMesh = aSubMesh->GetFather();
395 aSO = PublishSubMesh( theStudy, aMesh, aSubMesh, aShapeObject, theName );
398 // Publishing a hypothesis or algorithm
399 SMESH::SMESH_Hypothesis_var aHyp = SMESH::SMESH_Hypothesis::_narrow( theIOR );
400 if ( aSO->_is_nil() && !aHyp->_is_nil() )
401 aSO = PublishHypothesis( theStudy, aHyp );
403 // Publishing a group
404 SMESH::SMESH_GroupBase_var aGroup = SMESH::SMESH_GroupBase::_narrow(theIOR);
405 if ( aSO->_is_nil() && !aGroup->_is_nil() ) {
406 GEOM::GEOM_Object_var aShapeObject;
407 aMesh = aGroup->GetMesh();
408 aSO = PublishGroup( theStudy, aMesh, aGroup, aShapeObject, theName );
410 if(MYDEBUG) MESSAGE("PublishInStudy_END");
415 //=======================================================================
416 //function : PublishComponent
418 //=======================================================================
420 SALOMEDS::SComponent_ptr SMESH_Gen_i::PublishComponent(SALOMEDS::Study_ptr theStudy)
422 if ( CORBA::is_nil( theStudy ))
423 return SALOMEDS::SComponent::_nil();
424 if(MYDEBUG) MESSAGE("PublishComponent");
426 SALOMEDS::SComponent_var father =
427 SALOMEDS::SComponent::_narrow( theStudy->FindComponent( ComponentDataType() ) );
428 if ( !CORBA::is_nil( father ) )
429 return father._retn();
431 SALOME_ModuleCatalog::ModuleCatalog_var aCat =
432 SALOME_ModuleCatalog::ModuleCatalog::_narrow( GetNS()->Resolve("/Kernel/ModulCatalog") );
433 if ( CORBA::is_nil( aCat ) )
434 return father._retn();
436 SALOME_ModuleCatalog::Acomponent_var aComp = aCat->GetComponent( ComponentDataType() );
437 if ( CORBA::is_nil( aComp ) )
438 return father._retn();
440 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
441 SALOMEDS::GenericAttribute_var anAttr;
442 SALOMEDS::AttributePixMap_var aPixmap;
444 father = aStudyBuilder->NewComponent( ComponentDataType() );
445 aStudyBuilder->DefineComponentInstance( father, SMESH_Gen::_this() );
446 anAttr = aStudyBuilder->FindOrCreateAttribute( father, "AttributePixMap" );
447 aPixmap = SALOMEDS::AttributePixMap::_narrow( anAttr );
448 aPixmap ->SetPixMap( "ICON_OBJBROWSER_SMESH" );
449 SetName( father, aComp->componentusername(), "MESH" );
450 if(MYDEBUG) MESSAGE("PublishComponent--END");
452 return father._retn();
455 //=============================================================================
457 * findMaxChildTag [ static internal ]
459 * Finds maximum child tag for the given object
461 //=============================================================================
463 static long findMaxChildTag( SALOMEDS::SObject_ptr theSObject )
466 if ( !theSObject->_is_nil() ) {
467 SALOMEDS::Study_var aStudy = theSObject->GetStudy();
468 if ( !aStudy->_is_nil() ) {
469 SALOMEDS::ChildIterator_var anIter = aStudy->NewChildIterator( theSObject );
470 for ( ; anIter->More(); anIter->Next() ) {
471 long nTag = anIter->Value()->Tag();
480 //=======================================================================
481 //function : PublishMesh
483 //=======================================================================
485 SALOMEDS::SObject_ptr SMESH_Gen_i::PublishMesh (SALOMEDS::Study_ptr theStudy,
486 SMESH::SMESH_Mesh_ptr theMesh,
489 if ( CORBA::is_nil( theStudy ) ||
490 CORBA::is_nil( theMesh ))
491 return SALOMEDS::SComponent::_nil();
492 if(MYDEBUG) MESSAGE("PublishMesh--IN");
494 // find or publish a mesh
496 SALOMEDS::SObject_var aMeshSO = ObjectToSObject( theStudy, theMesh );
497 if ( aMeshSO->_is_nil() )
499 SALOMEDS::SComponent_var father = PublishComponent( theStudy );
500 if ( father->_is_nil() )
501 return aMeshSO._retn();
503 // Find correct free tag
504 long aTag = findMaxChildTag( father.in() );
505 if ( aTag <= GetAlgorithmsRootTag() )
506 aTag = GetAlgorithmsRootTag() + 1;
510 aMeshSO = publish (theStudy, theMesh, father, aTag, "ICON_SMESH_TREE_MESH_WARN" );
511 if ( aMeshSO->_is_nil() )
512 return aMeshSO._retn();
514 SetName( aMeshSO, theName, "Mesh" );
516 // Add shape reference
518 GEOM::GEOM_Object_var aShapeObject = theMesh->GetShapeToMesh();
519 if ( !CORBA::is_nil( aShapeObject )) {
520 addReference( theStudy, aMeshSO, aShapeObject, GetRefOnShapeTag() );
522 // Publish global hypotheses
524 SMESH::ListOfHypothesis_var hypList = theMesh->GetHypothesisList( aShapeObject );
525 for ( int i = 0; i < hypList->length(); i++ ) {
526 SMESH::SMESH_Hypothesis_var aHyp = SMESH::SMESH_Hypothesis::_narrow( hypList[ i ]);
527 PublishHypothesis( theStudy, aHyp );
528 AddHypothesisToShape( theStudy, theMesh, aShapeObject, aHyp );
534 SMESH_Mesh_i* mesh_i = objectToServant<SMESH_Mesh_i>( theMesh );
536 return aMeshSO._retn();
537 map<int, SMESH_subMesh_i*>& subMap = mesh_i->_mapSubMesh_i;
538 map<int, SMESH_subMesh_i*>::iterator subIt = subMap.begin();
539 for ( ; subIt != subMap.end(); subIt++ ) {
540 SMESH::SMESH_subMesh_ptr aSubMesh = (*subIt).second->_this();
541 if ( !CORBA::is_nil( aSubMesh )) {
542 aShapeObject = aSubMesh->GetSubShape();
543 PublishSubMesh( theStudy, theMesh, aSubMesh, aShapeObject );
548 const map<int, SMESH::SMESH_GroupBase_ptr>& grMap = mesh_i->getGroups();
549 map<int, SMESH::SMESH_GroupBase_ptr>::const_iterator it = grMap.begin();
550 for ( ; it != grMap.end(); it++ )
552 SMESH::SMESH_GroupBase_ptr aGroup = (*it).second;
553 if ( !aGroup->_is_nil() ) {
554 GEOM::GEOM_Object_var aShapeObj;
555 SMESH::SMESH_GroupOnGeom_var aGeomGroup =
556 SMESH::SMESH_GroupOnGeom::_narrow( aGroup );
557 if ( !aGeomGroup->_is_nil() )
558 aShapeObj = aGeomGroup->GetShape();
559 PublishGroup( theStudy, theMesh, aGroup, aShapeObj );
563 // Update string attribute (to display used variables)
564 // Temporarily commented (see implementation of SMESH_Mesh_i::UpdateStringAttribute())
565 //if( SMESH_Mesh_i* aServant = dynamic_cast<SMESH_Mesh_i*>( GetServant( theMesh ).in() ) )
566 // aServant->UpdateStringAttribute();
568 if(MYDEBUG) MESSAGE("PublishMesh_END");
569 return aMeshSO._retn();
572 //=======================================================================
573 //function : PublishSubMesh
575 //=======================================================================
577 SALOMEDS::SObject_ptr SMESH_Gen_i::PublishSubMesh (SALOMEDS::Study_ptr theStudy,
578 SMESH::SMESH_Mesh_ptr theMesh,
579 SMESH::SMESH_subMesh_ptr theSubMesh,
580 GEOM::GEOM_Object_ptr theShapeObject,
583 if (theStudy->_is_nil() || theMesh->_is_nil() ||
584 theSubMesh->_is_nil() || theShapeObject->_is_nil() )
585 return SALOMEDS::SObject::_nil();
587 SALOMEDS::SObject_var aSubMeshSO = ObjectToSObject( theStudy, theSubMesh );
588 if ( aSubMeshSO->_is_nil() )
590 SALOMEDS::SObject_var aMeshSO = ObjectToSObject( theStudy, theMesh );
591 if ( aMeshSO->_is_nil() ) {
592 aMeshSO = PublishMesh( theStudy, theMesh );
593 if ( aMeshSO->_is_nil())
594 return SALOMEDS::SObject::_nil();
596 // Find submesh sub-tree tag
598 const char* aRootName = "";
599 switch ( theShapeObject->GetShapeType() ) {
601 aRootTag = GetSubMeshOnVertexTag();
602 aRootName = "SubMeshes on Vertex";
605 aRootTag = GetSubMeshOnEdgeTag();
606 aRootName = "SubMeshes on Edge";
609 aRootTag = GetSubMeshOnWireTag();
610 aRootName = "SubMeshes on Wire";
613 aRootTag = GetSubMeshOnFaceTag();
614 aRootName = "SubMeshes on Face";
617 aRootTag = GetSubMeshOnShellTag();
618 aRootName = "SubMeshes on Shell";
621 aRootTag = GetSubMeshOnSolidTag();
622 aRootName = "SubMeshes on Solid";
625 aRootTag = GetSubMeshOnCompoundTag();
626 aRootName = "SubMeshes on Compound";
630 // Find or create submesh root
631 SALOMEDS::SObject_var aRootSO = publish (theStudy, CORBA::Object::_nil(),
632 aMeshSO, aRootTag, 0, false );
633 SetName( aRootSO, aRootName );
635 // Add new submesh to corresponding sub-tree
636 aSubMeshSO = publish (theStudy, theSubMesh, aRootSO, 0, "ICON_SMESH_TREE_MESH_WARN");
637 if ( aSubMeshSO->_is_nil() )
638 return aSubMeshSO._retn();
640 SetName( aSubMeshSO, theName, "SubMesh" );
642 // Add reference to theShapeObject
644 addReference( theStudy, aSubMeshSO, theShapeObject, 1 );
646 // Publish hypothesis
648 SMESH::ListOfHypothesis * hypList = theMesh->GetHypothesisList( theShapeObject );
650 for ( int i = 0; i < hypList->length(); i++ ) {
651 SMESH::SMESH_Hypothesis_var aHyp = SMESH::SMESH_Hypothesis::_narrow( (*hypList)[ i ]);
652 PublishHypothesis( theStudy, aHyp );
653 AddHypothesisToShape( theStudy, theMesh, theShapeObject, aHyp );
656 return aSubMeshSO._retn();
659 //=======================================================================
660 //function : PublishGroup
662 //=======================================================================
664 SALOMEDS::SObject_ptr SMESH_Gen_i::PublishGroup (SALOMEDS::Study_ptr theStudy,
665 SMESH::SMESH_Mesh_ptr theMesh,
666 SMESH::SMESH_GroupBase_ptr theGroup,
667 GEOM::GEOM_Object_ptr theShapeObject,
670 if (theStudy->_is_nil() || theMesh->_is_nil() || theGroup->_is_nil() )
671 return SALOMEDS::SObject::_nil();
673 SALOMEDS::SObject_var aGroupSO = ObjectToSObject( theStudy, theGroup );
674 if ( aGroupSO->_is_nil() )
676 SALOMEDS::SObject_var aMeshSO = ObjectToSObject( theStudy, theMesh );
677 if ( aMeshSO->_is_nil() ) {
678 aMeshSO = PublishInStudy( theStudy, SALOMEDS::SObject::_nil(), theMesh, "");
679 if ( aMeshSO->_is_nil())
680 return SALOMEDS::SObject::_nil();
682 int aType = (int)theGroup->GetType();
683 const char* aRootNames[] = {
684 "Compound Groups", "Groups of Nodes", "Groups of Edges",
685 "Groups of Faces", "Groups of Volumes", "Groups of 0D Elements" };
687 // Currently, groups with heterogenous content are not supported
688 if ( aType != SMESH::ALL ) {
689 long aRootTag = GetNodeGroupsTag() + aType - 1;
691 // Find or create groups root
692 SALOMEDS::SObject_var aRootSO = publish (theStudy, CORBA::Object::_nil(),
693 aMeshSO, aRootTag, 0, false );
695 SetName( aRootSO, aRootNames[aType] );
697 // Add new group to corresponding sub-tree
698 aGroupSO = publish (theStudy, theGroup, aRootSO, 0, "ICON_SMESH_TREE_GROUP" );
700 if ( aGroupSO->_is_nil() )
701 return aGroupSO._retn();
704 SetName( aGroupSO, theName, "Group" );
706 //Add reference to geometry
707 if ( !theShapeObject->_is_nil() )
708 addReference( theStudy, aGroupSO, theShapeObject, 1 );
710 return aGroupSO._retn();
713 //=======================================================================
714 //function : PublishHypothesis
716 //=======================================================================
718 SALOMEDS::SObject_ptr
719 SMESH_Gen_i::PublishHypothesis (SALOMEDS::Study_ptr theStudy,
720 SMESH::SMESH_Hypothesis_ptr theHyp,
723 if(MYDEBUG) MESSAGE("PublishHypothesis")
724 if (theStudy->_is_nil() || theHyp->_is_nil())
725 return SALOMEDS::SObject::_nil();
727 SALOMEDS::SObject_var aHypSO = ObjectToSObject( theStudy, theHyp );
728 if ( aHypSO->_is_nil() )
730 SALOMEDS::SComponent_var father = PublishComponent( theStudy );
731 if ( father->_is_nil() )
732 return aHypSO._retn();
734 //Find or Create Hypothesis root
735 bool isAlgo = ( !SMESH::SMESH_Algo::_narrow( theHyp )->_is_nil() );
736 int aRootTag = isAlgo ? GetAlgorithmsRootTag() : GetHypothesisRootTag();
737 SALOMEDS::SObject_var aRootSO =
738 publish (theStudy, CORBA::Object::_nil(),father, aRootTag,
739 isAlgo ? "ICON_SMESH_TREE_ALGO" : "ICON_SMESH_TREE_HYPO", false);
740 SetName( aRootSO, isAlgo ? "Algorithms" : "Hypotheses" );
742 // Add New Hypothesis
743 string aPmName = isAlgo ? "ICON_SMESH_TREE_ALGO_" : "ICON_SMESH_TREE_HYPO_";
744 aPmName += theHyp->GetName();
745 // prepend plugin name to pixmap name
746 string pluginName = myHypCreatorMap[string(theHyp->GetName())]->GetModuleName();
747 if ( pluginName != "StdMeshers" )
748 aPmName = pluginName + "::" + aPmName;
749 aHypSO = publish( theStudy, theHyp, aRootSO, 0, aPmName.c_str() );
752 if ( !aHypSO->_is_nil() ) {
753 CORBA::String_var aHypName = CORBA::string_dup( theHyp->GetName() );
754 SetName( aHypSO, theName, aHypName );
757 // Update string attribute (to display used variables)
758 if( SMESH_Hypothesis_i* aServant = dynamic_cast<SMESH_Hypothesis_i*>( GetServant( theHyp ).in() ) )
759 aServant->UpdateStringAttribute();
761 if(MYDEBUG) MESSAGE("PublishHypothesis--END")
762 return aHypSO._retn();
765 //=======================================================================
766 //function : GetMeshOrSubmeshByShape
768 //=======================================================================
770 SALOMEDS::SObject_ptr
771 SMESH_Gen_i::GetMeshOrSubmeshByShape (SALOMEDS::Study_ptr theStudy,
772 SMESH::SMESH_Mesh_ptr theMesh,
773 GEOM::GEOM_Object_ptr theShape)
775 if(MYDEBUG) MESSAGE("GetMeshOrSubmeshByShape")
776 SALOMEDS::SObject_var aMeshOrSubMesh;
777 if (theMesh->_is_nil() || ( theShape->_is_nil() && theMesh->HasShapeToMesh()))
778 return aMeshOrSubMesh._retn();
781 if(theMesh->HasShapeToMesh())
782 aShape = GeomObjectToShape( theShape );
784 aShape = SMESH_Mesh::PseudoShape();
786 SMESH_Mesh_i* mesh_i = objectToServant<SMESH_Mesh_i>( theMesh );
788 if ( !aShape.IsNull() && mesh_i && mesh_i->GetImpl().GetMeshDS() ) {
789 SMESHDS_Mesh* meshDS = mesh_i->GetImpl().GetMeshDS();
790 if ( aShape.IsSame( meshDS->ShapeToMesh() ))
791 aMeshOrSubMesh = ObjectToSObject( theStudy, theMesh );
793 int shapeID = meshDS->ShapeToIndex( aShape );
794 SMESH::SMESH_subMesh_var aSubMesh = mesh_i->getSubMesh(shapeID);
795 if ( !aSubMesh->_is_nil() )
796 aMeshOrSubMesh = ObjectToSObject( theStudy, aSubMesh );
799 if(MYDEBUG) MESSAGE("GetMeshOrSubmeshByShape--END")
800 return aMeshOrSubMesh._retn();
803 //=======================================================================
804 //function : AddHypothesisToShape
806 //=======================================================================
808 bool SMESH_Gen_i::AddHypothesisToShape(SALOMEDS::Study_ptr theStudy,
809 SMESH::SMESH_Mesh_ptr theMesh,
810 GEOM::GEOM_Object_ptr theShape,
811 SMESH::SMESH_Hypothesis_ptr theHyp)
813 if(MYDEBUG) MESSAGE("AddHypothesisToShape")
814 if (theStudy->_is_nil() || theMesh->_is_nil() ||
815 theHyp->_is_nil() || (theShape->_is_nil()
816 && theMesh->HasShapeToMesh()) )
819 SALOMEDS::SObject_var aMeshSO = ObjectToSObject( theStudy, theMesh );
820 if ( aMeshSO->_is_nil() )
821 aMeshSO = PublishMesh( theStudy, theMesh );
822 SALOMEDS::SObject_var aHypSO = PublishHypothesis( theStudy, theHyp );
823 if ( aMeshSO->_is_nil() || 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 TopoDS_Shape aShape = GeomObjectToShape( theShape );
833 SMESH_Mesh_i* mesh_i = objectToServant<SMESH_Mesh_i>( theMesh );
834 if ( !aShape.IsNull() && mesh_i && mesh_i->GetImpl().GetMeshDS() ) {
835 SMESHDS_Mesh* meshDS = mesh_i->GetImpl().GetMeshDS();
836 int shapeID = meshDS->ShapeToIndex( aShape );
837 SMESH::SMESH_subMesh_var aSubMesh = mesh_i->getSubMesh(shapeID);
838 aMeshOrSubMesh = PublishSubMesh( theStudy, theMesh, aSubMesh, theShape );
840 if ( aMeshOrSubMesh->_is_nil() )
844 //Find or Create Applied Hypothesis root
845 bool aIsAlgo = !SMESH::SMESH_Algo::_narrow( theHyp )->_is_nil();
846 SALOMEDS::SObject_var AHR =
847 publish (theStudy, CORBA::Object::_nil(), aMeshOrSubMesh,
848 aIsAlgo ? GetRefOnAppliedAlgorithmsTag() : GetRefOnAppliedHypothesisTag(),
849 aIsAlgo ? "ICON_SMESH_TREE_ALGO" : "ICON_SMESH_TREE_HYPO", false);
850 SetName( AHR, aIsAlgo ? "Applied algorithms" : "Applied hypotheses" );
851 if ( AHR->_is_nil() )
854 addReference( theStudy, AHR, theHyp );
855 if(MYDEBUG) MESSAGE("AddHypothesisToShape--END")
859 //=======================================================================
860 //function : RemoveHypothesisFromShape
862 //=======================================================================
864 bool SMESH_Gen_i::RemoveHypothesisFromShape(SALOMEDS::Study_ptr theStudy,
865 SMESH::SMESH_Mesh_ptr theMesh,
866 GEOM::GEOM_Object_ptr theShape,
867 SMESH::SMESH_Hypothesis_ptr theHyp)
869 if (theStudy->_is_nil() || theMesh->_is_nil() ||
870 theHyp->_is_nil() || (theShape->_is_nil()
871 && theMesh->HasShapeToMesh()))
874 SALOMEDS::SObject_var aHypSO = ObjectToSObject( theStudy, theHyp );
875 if ( aHypSO->_is_nil() )
878 // Find a mesh or submesh refering to theShape
879 SALOMEDS::SObject_var aMeshOrSubMesh =
880 GetMeshOrSubmeshByShape( theStudy, theMesh, theShape );
881 if ( aMeshOrSubMesh->_is_nil() )
884 // Find and remove a reference to aHypSO
885 SALOMEDS::SObject_var aRef, anObj;
886 CORBA::String_var anID = CORBA::string_dup( aHypSO->GetID() );
887 SALOMEDS::ChildIterator_var it = theStudy->NewChildIterator( aMeshOrSubMesh );
888 for ( it->InitEx( true ); it->More(); it->Next() ) {
890 if (anObj->ReferencedObject( aRef ) && strcmp( aRef->GetID(), anID ) == 0 ) {
891 theStudy->NewBuilder()->RemoveObject( anObj );