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 if(MYDEBUG) MESSAGE("PublishMesh_END");
564 return aMeshSO._retn();
567 //=======================================================================
568 //function : PublishSubMesh
570 //=======================================================================
572 SALOMEDS::SObject_ptr SMESH_Gen_i::PublishSubMesh (SALOMEDS::Study_ptr theStudy,
573 SMESH::SMESH_Mesh_ptr theMesh,
574 SMESH::SMESH_subMesh_ptr theSubMesh,
575 GEOM::GEOM_Object_ptr theShapeObject,
578 if (theStudy->_is_nil() || theMesh->_is_nil() ||
579 theSubMesh->_is_nil() || theShapeObject->_is_nil() )
580 return SALOMEDS::SObject::_nil();
582 SALOMEDS::SObject_var aSubMeshSO = ObjectToSObject( theStudy, theSubMesh );
583 if ( aSubMeshSO->_is_nil() )
585 SALOMEDS::SObject_var aMeshSO = ObjectToSObject( theStudy, theMesh );
586 if ( aMeshSO->_is_nil() ) {
587 aMeshSO = PublishMesh( theStudy, theMesh );
588 if ( aMeshSO->_is_nil())
589 return SALOMEDS::SObject::_nil();
591 // Find submesh sub-tree tag
593 const char* aRootName = "";
594 switch ( theShapeObject->GetShapeType() ) {
596 aRootTag = GetSubMeshOnVertexTag();
597 aRootName = "SubMeshes on Vertex";
600 aRootTag = GetSubMeshOnEdgeTag();
601 aRootName = "SubMeshes on Edge";
604 aRootTag = GetSubMeshOnWireTag();
605 aRootName = "SubMeshes on Wire";
608 aRootTag = GetSubMeshOnFaceTag();
609 aRootName = "SubMeshes on Face";
612 aRootTag = GetSubMeshOnShellTag();
613 aRootName = "SubMeshes on Shell";
616 aRootTag = GetSubMeshOnSolidTag();
617 aRootName = "SubMeshes on Solid";
620 aRootTag = GetSubMeshOnCompoundTag();
621 aRootName = "SubMeshes on Compound";
625 // Find or create submesh root
626 SALOMEDS::SObject_var aRootSO = publish (theStudy, CORBA::Object::_nil(),
627 aMeshSO, aRootTag, 0, false );
628 SetName( aRootSO, aRootName );
630 // Add new submesh to corresponding sub-tree
631 aSubMeshSO = publish (theStudy, theSubMesh, aRootSO, 0, "ICON_SMESH_TREE_MESH_WARN");
632 if ( aSubMeshSO->_is_nil() )
633 return aSubMeshSO._retn();
635 SetName( aSubMeshSO, theName, "SubMesh" );
637 // Add reference to theShapeObject
639 addReference( theStudy, aSubMeshSO, theShapeObject, 1 );
641 // Publish hypothesis
643 SMESH::ListOfHypothesis * hypList = theMesh->GetHypothesisList( theShapeObject );
645 for ( int i = 0; i < hypList->length(); i++ ) {
646 SMESH::SMESH_Hypothesis_var aHyp = SMESH::SMESH_Hypothesis::_narrow( (*hypList)[ i ]);
647 PublishHypothesis( theStudy, aHyp );
648 AddHypothesisToShape( theStudy, theMesh, theShapeObject, aHyp );
651 return aSubMeshSO._retn();
654 //=======================================================================
655 //function : PublishGroup
657 //=======================================================================
659 SALOMEDS::SObject_ptr SMESH_Gen_i::PublishGroup (SALOMEDS::Study_ptr theStudy,
660 SMESH::SMESH_Mesh_ptr theMesh,
661 SMESH::SMESH_GroupBase_ptr theGroup,
662 GEOM::GEOM_Object_ptr theShapeObject,
665 if (theStudy->_is_nil() || theMesh->_is_nil() || theGroup->_is_nil() )
666 return SALOMEDS::SObject::_nil();
668 SALOMEDS::SObject_var aGroupSO = ObjectToSObject( theStudy, theGroup );
669 if ( aGroupSO->_is_nil() )
671 SALOMEDS::SObject_var aMeshSO = ObjectToSObject( theStudy, theMesh );
672 if ( aMeshSO->_is_nil() ) {
673 aMeshSO = PublishInStudy( theStudy, SALOMEDS::SObject::_nil(), theMesh, "");
674 if ( aMeshSO->_is_nil())
675 return SALOMEDS::SObject::_nil();
677 int aType = (int)theGroup->GetType();
678 const char* aRootNames[] = {
679 "Compound Groups", "Groups of Nodes", "Groups of Edges",
680 "Groups of Faces", "Groups of Volumes", "Groups of 0D Elements" };
682 // Currently, groups with heterogenous content are not supported
683 if ( aType != SMESH::ALL ) {
684 long aRootTag = GetNodeGroupsTag() + aType - 1;
686 // Find or create groups root
687 SALOMEDS::SObject_var aRootSO = publish (theStudy, CORBA::Object::_nil(),
688 aMeshSO, aRootTag, 0, false );
690 SetName( aRootSO, aRootNames[aType] );
692 // Add new group to corresponding sub-tree
693 aGroupSO = publish (theStudy, theGroup, aRootSO, 0, "ICON_SMESH_TREE_GROUP" );
695 if ( aGroupSO->_is_nil() )
696 return aGroupSO._retn();
699 SetName( aGroupSO, theName, "Group" );
701 //Add reference to geometry
702 if ( !theShapeObject->_is_nil() )
703 addReference( theStudy, aGroupSO, theShapeObject, 1 );
705 return aGroupSO._retn();
708 //=======================================================================
709 //function : PublishHypothesis
711 //=======================================================================
713 SALOMEDS::SObject_ptr
714 SMESH_Gen_i::PublishHypothesis (SALOMEDS::Study_ptr theStudy,
715 SMESH::SMESH_Hypothesis_ptr theHyp,
718 if(MYDEBUG) MESSAGE("PublishHypothesis")
719 if (theStudy->_is_nil() || theHyp->_is_nil())
720 return SALOMEDS::SObject::_nil();
722 SALOMEDS::SObject_var aHypSO = ObjectToSObject( theStudy, theHyp );
723 if ( aHypSO->_is_nil() )
725 SALOMEDS::SComponent_var father = PublishComponent( theStudy );
726 if ( father->_is_nil() )
727 return aHypSO._retn();
729 //Find or Create Hypothesis root
730 bool isAlgo = ( !SMESH::SMESH_Algo::_narrow( theHyp )->_is_nil() );
731 int aRootTag = isAlgo ? GetAlgorithmsRootTag() : GetHypothesisRootTag();
732 SALOMEDS::SObject_var aRootSO =
733 publish (theStudy, CORBA::Object::_nil(),father, aRootTag,
734 isAlgo ? "ICON_SMESH_TREE_ALGO" : "ICON_SMESH_TREE_HYPO", false);
735 SetName( aRootSO, isAlgo ? "Algorithms" : "Hypotheses" );
737 // Add New Hypothesis
738 string aPmName = isAlgo ? "ICON_SMESH_TREE_ALGO_" : "ICON_SMESH_TREE_HYPO_";
739 aPmName += theHyp->GetName();
740 // prepend plugin name to pixmap name
741 string pluginName = myHypCreatorMap[string(theHyp->GetName())]->GetModuleName();
742 if ( pluginName != "StdMeshers" )
743 aPmName = pluginName + "::" + aPmName;
744 aHypSO = publish( theStudy, theHyp, aRootSO, 0, aPmName.c_str() );
747 if ( !aHypSO->_is_nil() ) {
748 CORBA::String_var aHypName = CORBA::string_dup( theHyp->GetName() );
749 SetName( aHypSO, theName, aHypName );
752 if(MYDEBUG) MESSAGE("PublishHypothesis--END")
753 return aHypSO._retn();
756 //=======================================================================
757 //function : GetMeshOrSubmeshByShape
759 //=======================================================================
761 SALOMEDS::SObject_ptr
762 SMESH_Gen_i::GetMeshOrSubmeshByShape (SALOMEDS::Study_ptr theStudy,
763 SMESH::SMESH_Mesh_ptr theMesh,
764 GEOM::GEOM_Object_ptr theShape)
766 if(MYDEBUG) MESSAGE("GetMeshOrSubmeshByShape")
767 SALOMEDS::SObject_var aMeshOrSubMesh;
768 if (theMesh->_is_nil() || ( theShape->_is_nil() && theMesh->HasShapeToMesh()))
769 return aMeshOrSubMesh._retn();
772 if(theMesh->HasShapeToMesh())
773 aShape = GeomObjectToShape( theShape );
775 aShape = SMESH_Mesh::PseudoShape();
777 SMESH_Mesh_i* mesh_i = objectToServant<SMESH_Mesh_i>( theMesh );
779 if ( !aShape.IsNull() && mesh_i && mesh_i->GetImpl().GetMeshDS() ) {
780 SMESHDS_Mesh* meshDS = mesh_i->GetImpl().GetMeshDS();
781 if ( aShape.IsSame( meshDS->ShapeToMesh() ))
782 aMeshOrSubMesh = ObjectToSObject( theStudy, theMesh );
784 int shapeID = meshDS->ShapeToIndex( aShape );
785 SMESH::SMESH_subMesh_var aSubMesh = mesh_i->getSubMesh(shapeID);
786 if ( !aSubMesh->_is_nil() )
787 aMeshOrSubMesh = ObjectToSObject( theStudy, aSubMesh );
790 if(MYDEBUG) MESSAGE("GetMeshOrSubmeshByShape--END")
791 return aMeshOrSubMesh._retn();
794 //=======================================================================
795 //function : AddHypothesisToShape
797 //=======================================================================
799 bool SMESH_Gen_i::AddHypothesisToShape(SALOMEDS::Study_ptr theStudy,
800 SMESH::SMESH_Mesh_ptr theMesh,
801 GEOM::GEOM_Object_ptr theShape,
802 SMESH::SMESH_Hypothesis_ptr theHyp)
804 if(MYDEBUG) MESSAGE("AddHypothesisToShape")
805 if (theStudy->_is_nil() || theMesh->_is_nil() ||
806 theHyp->_is_nil() || (theShape->_is_nil()
807 && theMesh->HasShapeToMesh()) )
810 SALOMEDS::SObject_var aMeshSO = ObjectToSObject( theStudy, theMesh );
811 if ( aMeshSO->_is_nil() )
812 aMeshSO = PublishMesh( theStudy, theMesh );
813 SALOMEDS::SObject_var aHypSO = PublishHypothesis( theStudy, theHyp );
814 if ( aMeshSO->_is_nil() || aHypSO->_is_nil())
817 // Find a mesh or submesh refering to theShape
818 SALOMEDS::SObject_var aMeshOrSubMesh =
819 GetMeshOrSubmeshByShape( theStudy, theMesh, theShape );
820 if ( aMeshOrSubMesh->_is_nil() )
823 TopoDS_Shape aShape = GeomObjectToShape( theShape );
824 SMESH_Mesh_i* mesh_i = objectToServant<SMESH_Mesh_i>( theMesh );
825 if ( !aShape.IsNull() && mesh_i && mesh_i->GetImpl().GetMeshDS() ) {
826 SMESHDS_Mesh* meshDS = mesh_i->GetImpl().GetMeshDS();
827 int shapeID = meshDS->ShapeToIndex( aShape );
828 SMESH::SMESH_subMesh_var aSubMesh = mesh_i->getSubMesh(shapeID);
829 aMeshOrSubMesh = PublishSubMesh( theStudy, theMesh, aSubMesh, theShape );
831 if ( aMeshOrSubMesh->_is_nil() )
835 //Find or Create Applied Hypothesis root
836 bool aIsAlgo = !SMESH::SMESH_Algo::_narrow( theHyp )->_is_nil();
837 SALOMEDS::SObject_var AHR =
838 publish (theStudy, CORBA::Object::_nil(), aMeshOrSubMesh,
839 aIsAlgo ? GetRefOnAppliedAlgorithmsTag() : GetRefOnAppliedHypothesisTag(),
840 aIsAlgo ? "ICON_SMESH_TREE_ALGO" : "ICON_SMESH_TREE_HYPO", false);
841 SetName( AHR, aIsAlgo ? "Applied algorithms" : "Applied hypotheses" );
842 if ( AHR->_is_nil() )
845 addReference( theStudy, AHR, theHyp );
846 if(MYDEBUG) MESSAGE("AddHypothesisToShape--END")
850 //=======================================================================
851 //function : RemoveHypothesisFromShape
853 //=======================================================================
855 bool SMESH_Gen_i::RemoveHypothesisFromShape(SALOMEDS::Study_ptr theStudy,
856 SMESH::SMESH_Mesh_ptr theMesh,
857 GEOM::GEOM_Object_ptr theShape,
858 SMESH::SMESH_Hypothesis_ptr theHyp)
860 if (theStudy->_is_nil() || theMesh->_is_nil() ||
861 theHyp->_is_nil() || (theShape->_is_nil()
862 && theMesh->HasShapeToMesh()))
865 SALOMEDS::SObject_var aHypSO = ObjectToSObject( theStudy, theHyp );
866 if ( aHypSO->_is_nil() )
869 // Find a mesh or submesh refering to theShape
870 SALOMEDS::SObject_var aMeshOrSubMesh =
871 GetMeshOrSubmeshByShape( theStudy, theMesh, theShape );
872 if ( aMeshOrSubMesh->_is_nil() )
875 // Find and remove a reference to aHypSO
876 SALOMEDS::SObject_var aRef, anObj;
877 CORBA::String_var anID = CORBA::string_dup( aHypSO->GetID() );
878 SALOMEDS::ChildIterator_var it = theStudy->NewChildIterator( aMeshOrSubMesh );
879 for ( it->InitEx( true ); it->More(); it->Next() ) {
881 if (anObj->ReferencedObject( aRef ) && strcmp( aRef->GetID(), anID ) == 0 ) {
882 theStudy->NewBuilder()->RemoveObject( anObj );
889 //=======================================================================
890 //function : UpdateParameters
892 //=======================================================================
893 void SMESH_Gen_i::UpdateParameters(CORBA::Object_ptr theObject, const char* theParameters)
897 cout<<"UpdateParameters : "<<theParameters<<endl;
898 SALOMEDS::Study_ptr aStudy = GetCurrentStudy();
899 if(aStudy->_is_nil() || CORBA::is_nil(theObject))
902 SALOMEDS::SObject_var aSObj = ObjectToSObject(aStudy,theObject);
906 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
908 SALOMEDS::GenericAttribute_var aFindAttr;
909 bool hasAttr = aSObj->FindAttribute(aFindAttr, "AttributeString");
911 cout<<"Find Attribute "<<hasAttr<<endl;
913 SALOMEDS::GenericAttribute_var anAttr;
914 anAttr = aStudyBuilder->FindOrCreateAttribute( aSObj, "AttributeString");
915 SALOMEDS::AttributeString_var aStringAttr = SALOMEDS::AttributeString::_narrow(anAttr);
917 CORBA::String_var oldparVar = aStringAttr->Value();
918 CORBA::String_var inpparVar = ParseParameters(theParameters);
919 TCollection_AsciiString aNewParams;
920 TCollection_AsciiString aOldParameters(oldparVar.inout());
921 TCollection_AsciiString anInputParams(inpparVar.inout());
923 aNewParams = anInputParams;
925 aNewParams = aOldParameters+"|"+anInputParams;
929 cout<<"Input Parameters : "<<anInputParams<<endl;
930 cout<<"Old Parameters : "<<aOldParameters<<endl;
931 cout<<"New Parameters : "<<aNewParams<<endl;
934 aStringAttr->SetValue( aNewParams.ToCString() );
937 //=======================================================================
938 //function : ParseParameters
940 //=======================================================================
941 char* SMESH_Gen_i::ParseParameters(const char* theParameters)
943 /* ouv: temporarily disabled
944 //const char* aParameters = theParameters;
945 // const char* aParameters = CORBA::string_dup(theParameters);
946 TCollection_AsciiString anInputParams;
947 SALOMEDS::Study_var aStudy = GetCurrentStudy();
948 if( !aStudy->_is_nil() ) {
949 // SALOMEDS::ListOfListOfStrings_var aSections = aStudy->ParseVariables(theParameters);
950 // for(int j=0;j<aSections->length();j++) {
951 // SALOMEDS::ListOfStrings aVars= aSections[j];
952 // for(int i=0;i<aVars.length();i++ ) {
953 // anInputParams += aStudy->IsVariable(aVars[i].in()) ?
954 // TCollection_AsciiString(aVars[i].in()) : TCollection_AsciiString("");
955 // if(i != aVars.length()-1)
956 // anInputParams+=":";
958 // if(j!=aSections->length()-1)
959 // anInputParams+="|";
961 TCollection_AsciiString paramStr( theParameters );
962 static TCollection_AsciiString separators(":|");
964 char sep, *pParams = (char*)paramStr.ToCString();
965 while ( beg < paramStr.Length() )
968 while ( ++end < paramStr.Length() )
969 if ( pParams[end] == ':' || pParams[end] == '|')
971 if ( end < paramStr.Length())
976 if ( aStudy->IsVariable( pParams+beg ))
977 anInputParams += pParams+beg;
978 if ( end < paramStr.Length() )
979 anInputParams += sep;
985 return CORBA::string_dup(anInputParams.ToCString());
990 //=======================================================================
991 //function : GetParameters
993 //=======================================================================
994 char* SMESH_Gen_i::GetParameters(CORBA::Object_ptr theObject)
996 TCollection_AsciiString aResult;
998 SALOMEDS::Study_ptr aStudy = GetCurrentStudy();
999 SALOMEDS::SObject_var aSObj = ObjectToSObject(aStudy,theObject);
1001 if(!aStudy->_is_nil() &&
1002 !CORBA::is_nil(theObject) &&
1005 SALOMEDS::GenericAttribute_var anAttr;
1006 if ( aSObj->FindAttribute(anAttr, "AttributeString")) {
1007 aResult = TCollection_AsciiString(SALOMEDS::AttributeString::_narrow(anAttr)->Value());
1011 return CORBA::string_dup( aResult.ToCString() );