1 // SMESH SMESH_I : idl implementation based on 'SMESH' unit's calsses
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // File : SMESH_Gen_i_1.cxx
24 // Created : Thu Oct 21 17:24:06 2004
25 // Author : Edward AGAPOV (eap)
29 #include "SMESH_Gen_i.hxx"
31 #include "SMESH_Mesh_i.hxx"
32 #include "SMESH_Hypothesis_i.hxx"
33 #include "SMESH_Algo_i.hxx"
34 #include "SMESH_Group_i.hxx"
35 #include "SMESH_subMesh_i.hxx"
37 #include CORBA_CLIENT_HEADER(SALOME_ModuleCatalog)
39 #include "utilities.h"
40 #include "Utils_ExceptHandlers.hxx"
42 #include <TCollection_AsciiString.hxx>
45 static int MYDEBUG = 0;
46 static int VARIABLE_DEBUG = 1;
48 static int MYDEBUG = 0;
49 static int VARIABLE_DEBUG = 1;
55 //=============================================================================
57 * Get...Tag [ static ]
59 * Methods which determine SMESH data model structure
61 //=============================================================================
63 long SMESH_Gen_i::GetHypothesisRootTag()
65 return SMESH::Tag_HypothesisRoot;
68 long SMESH_Gen_i::GetAlgorithmsRootTag()
70 return SMESH::Tag_AlgorithmsRoot;
73 long SMESH_Gen_i::GetRefOnShapeTag()
75 return SMESH::Tag_RefOnShape;
78 long SMESH_Gen_i::GetRefOnAppliedHypothesisTag()
80 return SMESH::Tag_RefOnAppliedHypothesis;
83 long SMESH_Gen_i::GetRefOnAppliedAlgorithmsTag()
85 return SMESH::Tag_RefOnAppliedAlgorithms;
88 long SMESH_Gen_i::GetSubMeshOnVertexTag()
90 return SMESH::Tag_SubMeshOnVertex;
93 long SMESH_Gen_i::GetSubMeshOnEdgeTag()
95 return SMESH::Tag_SubMeshOnEdge;
98 long SMESH_Gen_i::GetSubMeshOnFaceTag()
100 return SMESH::Tag_SubMeshOnFace;
103 long SMESH_Gen_i::GetSubMeshOnSolidTag()
105 return SMESH::Tag_SubMeshOnSolid;
108 long SMESH_Gen_i::GetSubMeshOnCompoundTag()
110 return SMESH::Tag_SubMeshOnCompound;
113 long SMESH_Gen_i::GetSubMeshOnWireTag()
115 return SMESH::Tag_SubMeshOnWire;
118 long SMESH_Gen_i::GetSubMeshOnShellTag()
120 return SMESH::Tag_SubMeshOnShell;
123 long SMESH_Gen_i::GetNodeGroupsTag()
125 return SMESH::Tag_NodeGroups;
128 long SMESH_Gen_i::GetEdgeGroupsTag()
130 return SMESH::Tag_EdgeGroups;
133 long SMESH_Gen_i::GetFaceGroupsTag()
135 return SMESH::Tag_FaceGroups;
138 long SMESH_Gen_i::GetVolumeGroupsTag()
140 return SMESH::Tag_VolumeGroups;
143 //=============================================================================
145 * SMESH_Gen_i::CanPublishInStudy
147 * Returns true if object can be published in the study
149 //=============================================================================
151 bool SMESH_Gen_i::CanPublishInStudy(CORBA::Object_ptr theIOR)
153 if(MYDEBUG) MESSAGE("CanPublishInStudy - "<<!CORBA::is_nil(myCurrentStudy));
154 if(CORBA::is_nil(myCurrentStudy))
157 SMESH::SMESH_Mesh_var aMesh = SMESH::SMESH_Mesh::_narrow(theIOR);
158 if( !aMesh->_is_nil() )
161 SMESH::SMESH_subMesh_var aSubMesh = SMESH::SMESH_subMesh::_narrow(theIOR);
162 if( !aSubMesh->_is_nil() )
165 SMESH::SMESH_Hypothesis_var aHyp = SMESH::SMESH_Hypothesis::_narrow(theIOR);
166 if( !aHyp->_is_nil() )
169 SMESH::SMESH_GroupBase_var aGroup = SMESH::SMESH_GroupBase::_narrow(theIOR);
170 if( !aGroup->_is_nil() )
173 if(MYDEBUG) MESSAGE("CanPublishInStudy--CANT");
177 //=======================================================================
178 //function : ObjectToSObject
180 //=======================================================================
182 SALOMEDS::SObject_ptr SMESH_Gen_i::ObjectToSObject(SALOMEDS::Study_ptr theStudy,
183 CORBA::Object_ptr theObject)
185 SALOMEDS::SObject_var aSO;
186 if ( !CORBA::is_nil( theStudy ) && !CORBA::is_nil( theObject ))
188 CORBA::String_var objStr = SMESH_Gen_i::GetORB()->object_to_string( theObject );
189 aSO = theStudy->FindObjectIOR( objStr.in() );
194 //=======================================================================
195 //function : objectToServant
197 //=======================================================================
199 template<typename T> static inline T* objectToServant( CORBA::Object_ptr theIOR )
201 return dynamic_cast<T*>( SMESH_Gen_i::GetServant( theIOR ).in() );
204 //=======================================================================
205 //function : ShapeToGeomObject
207 //=======================================================================
209 GEOM::GEOM_Object_ptr SMESH_Gen_i::ShapeToGeomObject (const TopoDS_Shape& theShape )
211 GEOM::GEOM_Object_var aShapeObj;
212 if ( !theShape.IsNull() ) {
213 GEOM_Client* aClient = GetShapeReader();
214 TCollection_AsciiString IOR;
215 if ( aClient && aClient->Find( theShape, IOR ))
216 aShapeObj = GEOM::GEOM_Object::_narrow
217 ( GetORB()->string_to_object( IOR.ToCString() ) );
219 return aShapeObj._retn();
222 //=======================================================================
223 //function : GeomObjectToShape
225 //=======================================================================
227 TopoDS_Shape SMESH_Gen_i::GeomObjectToShape(GEOM::GEOM_Object_ptr theGeomObject)
230 if ( !theGeomObject->_is_nil() ) {
231 GEOM_Client* aClient = GetShapeReader();
232 GEOM::GEOM_Gen_ptr aGeomEngine = GetGeomEngine();
233 if ( aClient && !aGeomEngine->_is_nil () )
234 S = aClient->GetShape( aGeomEngine, theGeomObject );
239 //=======================================================================
242 //=======================================================================
244 static SALOMEDS::SObject_ptr publish(SALOMEDS::Study_ptr theStudy,
245 CORBA::Object_ptr theIOR,
246 SALOMEDS::SObject_ptr theFatherObject,
247 const int theTag = 0,
248 const char* thePixMap = 0,
249 const bool theSelectable = true)
251 SALOMEDS::SObject_var SO = SMESH_Gen_i::ObjectToSObject( theStudy, theIOR );
252 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
253 if ( SO->_is_nil() ) {
255 SO = aStudyBuilder->NewObject( theFatherObject );
256 else if ( !theFatherObject->FindSubObject( theTag, SO ))
257 SO = aStudyBuilder->NewObjectToTag( theFatherObject, theTag );
260 SALOMEDS::GenericAttribute_var anAttr;
261 if ( !CORBA::is_nil( theIOR )) {
262 anAttr = aStudyBuilder->FindOrCreateAttribute( SO, "AttributeIOR" );
263 CORBA::String_var objStr = SMESH_Gen_i::GetORB()->object_to_string( theIOR );
264 SALOMEDS::AttributeIOR::_narrow(anAttr)->SetValue( objStr.in() );
267 anAttr = aStudyBuilder->FindOrCreateAttribute( SO, "AttributePixMap" );
268 SALOMEDS::AttributePixMap::_narrow( anAttr )->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 : addReference
307 //=======================================================================
309 static void addReference (SALOMEDS::Study_ptr theStudy,
310 SALOMEDS::SObject_ptr theSObject,
311 CORBA::Object_ptr theToObject,
314 SALOMEDS::SObject_var aToObjSO = SMESH_Gen_i::ObjectToSObject( theStudy, theToObject );
315 if ( !aToObjSO->_is_nil() && !theSObject->_is_nil() ) {
316 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
317 SALOMEDS::SObject_var aReferenceSO;
319 // check if the reference to theToObject already exists
320 // and find a free label for the reference object
321 bool isReferred = false;
323 SALOMEDS::ChildIterator_var anIter = theStudy->NewChildIterator( theSObject );
324 for ( ; !isReferred && anIter->More(); anIter->Next(), ++tag ) {
325 if ( anIter->Value()->ReferencedObject( aReferenceSO )) {
326 if ( strcmp( aReferenceSO->GetID(), aToObjSO->GetID() ) == 0 )
329 else if ( !theTag ) {
330 SALOMEDS::GenericAttribute_var anAttr;
331 if ( !anIter->Value()->FindAttribute( anAttr, "AttributeIOR" ))
340 if ( !theSObject->FindSubObject( theTag, aReferenceSO ))
341 aReferenceSO = aStudyBuilder->NewObjectToTag( theSObject, theTag );
342 aStudyBuilder->Addreference( aReferenceSO, aToObjSO );
346 //=============================================================================
348 * SMESH_Gen_i::PublishInStudy
350 * Publish object in the study
352 //=============================================================================
354 SALOMEDS::SObject_ptr SMESH_Gen_i::PublishInStudy(SALOMEDS::Study_ptr theStudy,
355 SALOMEDS::SObject_ptr theSObject,
356 CORBA::Object_ptr theIOR,
358 throw (SALOME::SALOME_Exception)
360 Unexpect aCatch(SALOME_SalomeException);
361 SALOMEDS::SObject_var aSO;
362 if ( CORBA::is_nil( theStudy ) || CORBA::is_nil( theIOR ))
364 if(MYDEBUG) MESSAGE("PublishInStudy");
367 SMESH::SMESH_Mesh_var aMesh = SMESH::SMESH_Mesh::_narrow( theIOR );
368 if( !aMesh->_is_nil() )
369 aSO = PublishMesh( theStudy, aMesh, theName );
371 // Publishing a sub-mesh
372 SMESH::SMESH_subMesh_var aSubMesh = SMESH::SMESH_subMesh::_narrow( theIOR );
373 if( aSO->_is_nil() && !aSubMesh->_is_nil() ) {
374 GEOM::GEOM_Object_var aShapeObject = aSubMesh->GetSubShape();
375 aMesh = aSubMesh->GetFather();
376 aSO = PublishSubMesh( theStudy, aMesh, aSubMesh, aShapeObject, theName );
379 // Publishing a hypothesis or algorithm
380 SMESH::SMESH_Hypothesis_var aHyp = SMESH::SMESH_Hypothesis::_narrow( theIOR );
381 if ( aSO->_is_nil() && !aHyp->_is_nil() )
382 aSO = PublishHypothesis( theStudy, aHyp );
384 // Publishing a group
385 SMESH::SMESH_GroupBase_var aGroup = SMESH::SMESH_GroupBase::_narrow(theIOR);
386 if ( aSO->_is_nil() && !aGroup->_is_nil() ) {
387 GEOM::GEOM_Object_var aShapeObject;
388 aMesh = aGroup->GetMesh();
389 aSO = PublishGroup( theStudy, aMesh, aGroup, aShapeObject, theName );
391 if(MYDEBUG) MESSAGE("PublishInStudy_END");
396 //=======================================================================
397 //function : PublishComponent
399 //=======================================================================
401 SALOMEDS::SComponent_ptr SMESH_Gen_i::PublishComponent(SALOMEDS::Study_ptr theStudy)
403 if ( CORBA::is_nil( theStudy ))
404 return SALOMEDS::SComponent::_nil();
405 if(MYDEBUG) MESSAGE("PublishComponent");
407 SALOMEDS::SComponent_var father =
408 SALOMEDS::SComponent::_narrow( theStudy->FindComponent( ComponentDataType() ) );
409 if ( !CORBA::is_nil( father ) )
410 return father._retn();
412 SALOME_ModuleCatalog::ModuleCatalog_var aCat =
413 SALOME_ModuleCatalog::ModuleCatalog::_narrow( GetNS()->Resolve("/Kernel/ModulCatalog") );
414 if ( CORBA::is_nil( aCat ) )
415 return father._retn();
417 SALOME_ModuleCatalog::Acomponent_var aComp = aCat->GetComponent( ComponentDataType() );
418 if ( CORBA::is_nil( aComp ) )
419 return father._retn();
421 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
422 SALOMEDS::GenericAttribute_var anAttr;
423 SALOMEDS::AttributePixMap_var aPixmap;
425 father = aStudyBuilder->NewComponent( ComponentDataType() );
426 aStudyBuilder->DefineComponentInstance( father, SMESH_Gen::_this() );
427 anAttr = aStudyBuilder->FindOrCreateAttribute( father, "AttributePixMap" );
428 aPixmap = SALOMEDS::AttributePixMap::_narrow( anAttr );
429 aPixmap ->SetPixMap( "ICON_OBJBROWSER_SMESH" );
430 SetName( father, aComp->componentusername(), "MESH" );
431 if(MYDEBUG) MESSAGE("PublishComponent--END");
433 return father._retn();
436 //=============================================================================
438 * findMaxChildTag [ static internal ]
440 * Finds maximum child tag for the given object
442 //=============================================================================
444 static long findMaxChildTag( SALOMEDS::SObject_ptr theSObject )
447 if ( !theSObject->_is_nil() ) {
448 SALOMEDS::Study_var aStudy = theSObject->GetStudy();
449 if ( !aStudy->_is_nil() ) {
450 SALOMEDS::ChildIterator_var anIter = aStudy->NewChildIterator( theSObject );
451 for ( ; anIter->More(); anIter->Next() ) {
452 long nTag = anIter->Value()->Tag();
461 //=======================================================================
462 //function : PublishMesh
464 //=======================================================================
466 SALOMEDS::SObject_ptr SMESH_Gen_i::PublishMesh (SALOMEDS::Study_ptr theStudy,
467 SMESH::SMESH_Mesh_ptr theMesh,
470 if ( CORBA::is_nil( theStudy ) ||
471 CORBA::is_nil( theMesh ))
472 return SALOMEDS::SComponent::_nil();
473 if(MYDEBUG) MESSAGE("PublishMesh--IN");
475 // find or publish a mesh
477 SALOMEDS::SObject_var aMeshSO = ObjectToSObject( theStudy, theMesh );
478 if ( aMeshSO->_is_nil() )
480 SALOMEDS::SComponent_var father = PublishComponent( theStudy );
481 if ( father->_is_nil() )
482 return aMeshSO._retn();
484 // Find correct free tag
485 long aTag = findMaxChildTag( father.in() );
486 if ( aTag <= GetAlgorithmsRootTag() )
487 aTag = GetAlgorithmsRootTag() + 1;
491 aMeshSO = publish (theStudy, theMesh, father, aTag, "ICON_SMESH_TREE_MESH_WARN" );
492 if ( aMeshSO->_is_nil() )
493 return aMeshSO._retn();
495 SetName( aMeshSO, theName, "Mesh" );
497 // Add shape reference
499 GEOM::GEOM_Object_var aShapeObject = theMesh->GetShapeToMesh();
500 if ( !CORBA::is_nil( aShapeObject )) {
501 addReference( theStudy, aMeshSO, aShapeObject, GetRefOnShapeTag() );
503 // Publish global hypotheses
505 SMESH::ListOfHypothesis * hypList = theMesh->GetHypothesisList( aShapeObject );
507 for ( int i = 0; i < hypList->length(); i++ ) {
508 SMESH::SMESH_Hypothesis_var aHyp = SMESH::SMESH_Hypothesis::_narrow( (*hypList)[ i ]);
509 PublishHypothesis( theStudy, aHyp );
510 AddHypothesisToShape( theStudy, theMesh, aShapeObject, aHyp );
516 SMESH_Mesh_i* mesh_i = objectToServant<SMESH_Mesh_i>( theMesh );
518 return aMeshSO._retn();
519 map<int, SMESH_subMesh_i*>& subMap = mesh_i->_mapSubMesh_i;
520 map<int, SMESH_subMesh_i*>::iterator subIt = subMap.begin();
521 for ( ; subIt != subMap.end(); subIt++ ) {
522 SMESH::SMESH_subMesh_ptr aSubMesh = (*subIt).second->_this();
523 if ( !CORBA::is_nil( aSubMesh )) {
524 aShapeObject = aSubMesh->GetSubShape();
525 PublishSubMesh( theStudy, theMesh, aSubMesh, aShapeObject );
530 const map<int, SMESH::SMESH_GroupBase_ptr>& grMap = mesh_i->getGroups();
531 map<int, SMESH::SMESH_GroupBase_ptr>::const_iterator it = grMap.begin();
532 for ( ; it != grMap.end(); it++ )
534 SMESH::SMESH_GroupBase_ptr aGroup = (*it).second;
535 if ( !aGroup->_is_nil() ) {
536 GEOM::GEOM_Object_var aShapeObj;
537 SMESH::SMESH_GroupOnGeom_var aGeomGroup =
538 SMESH::SMESH_GroupOnGeom::_narrow( aGroup );
539 if ( !aGeomGroup->_is_nil() )
540 aShapeObj = aGeomGroup->GetShape();
541 PublishGroup( theStudy, theMesh, aGroup, aShapeObj );
545 if(MYDEBUG) MESSAGE("PublishMesh_END");
546 return aMeshSO._retn();
549 //=======================================================================
550 //function : PublishSubMesh
552 //=======================================================================
554 SALOMEDS::SObject_ptr SMESH_Gen_i::PublishSubMesh (SALOMEDS::Study_ptr theStudy,
555 SMESH::SMESH_Mesh_ptr theMesh,
556 SMESH::SMESH_subMesh_ptr theSubMesh,
557 GEOM::GEOM_Object_ptr theShapeObject,
560 if (theStudy->_is_nil() || theMesh->_is_nil() ||
561 theSubMesh->_is_nil() || theShapeObject->_is_nil() )
562 return SALOMEDS::SObject::_nil();
564 SALOMEDS::SObject_var aSubMeshSO = ObjectToSObject( theStudy, theSubMesh );
565 if ( aSubMeshSO->_is_nil() )
567 SALOMEDS::SObject_var aMeshSO = ObjectToSObject( theStudy, theMesh );
568 if ( aMeshSO->_is_nil() ) {
569 aMeshSO = PublishMesh( theStudy, theMesh );
570 if ( aMeshSO->_is_nil())
571 return SALOMEDS::SObject::_nil();
573 // Find submesh sub-tree tag
575 char* aRootName = "";
576 switch ( theShapeObject->GetShapeType() ) {
578 aRootTag = GetSubMeshOnVertexTag();
579 aRootName = "SubMeshes on Vertex";
582 aRootTag = GetSubMeshOnEdgeTag();
583 aRootName = "SubMeshes on Edge";
586 aRootTag = GetSubMeshOnWireTag();
587 aRootName = "SubMeshes on Wire";
590 aRootTag = GetSubMeshOnFaceTag();
591 aRootName = "SubMeshes on Face";
594 aRootTag = GetSubMeshOnShellTag();
595 aRootName = "SubMeshes on Shell";
598 aRootTag = GetSubMeshOnSolidTag();
599 aRootName = "SubMeshes on Solid";
602 aRootTag = GetSubMeshOnCompoundTag();
603 aRootName = "SubMeshes on Compound";
607 // Find or create submesh root
608 SALOMEDS::SObject_var aRootSO = publish (theStudy, CORBA::Object::_nil(),
609 aMeshSO, aRootTag, 0, false );
610 SetName( aRootSO, aRootName );
612 // Add new submesh to corresponding sub-tree
613 aSubMeshSO = publish (theStudy, theSubMesh, aRootSO, 0, "ICON_SMESH_TREE_MESH_WARN");
614 if ( aSubMeshSO->_is_nil() )
615 return aSubMeshSO._retn();
617 SetName( aSubMeshSO, theName, "SubMesh" );
619 // Add reference to theShapeObject
621 addReference( theStudy, aSubMeshSO, theShapeObject, 1 );
623 // Publish hypothesis
625 SMESH::ListOfHypothesis * hypList = theMesh->GetHypothesisList( theShapeObject );
627 for ( int i = 0; i < hypList->length(); i++ ) {
628 SMESH::SMESH_Hypothesis_var aHyp = SMESH::SMESH_Hypothesis::_narrow( (*hypList)[ i ]);
629 PublishHypothesis( theStudy, aHyp );
630 AddHypothesisToShape( theStudy, theMesh, theShapeObject, aHyp );
633 return aSubMeshSO._retn();
636 //=======================================================================
637 //function : PublishGroup
639 //=======================================================================
641 SALOMEDS::SObject_ptr SMESH_Gen_i::PublishGroup (SALOMEDS::Study_ptr theStudy,
642 SMESH::SMESH_Mesh_ptr theMesh,
643 SMESH::SMESH_GroupBase_ptr theGroup,
644 GEOM::GEOM_Object_ptr theShapeObject,
647 if (theStudy->_is_nil() || theMesh->_is_nil() || theGroup->_is_nil() )
648 return SALOMEDS::SObject::_nil();
650 SALOMEDS::SObject_var aGroupSO = ObjectToSObject( theStudy, theGroup );
651 if ( aGroupSO->_is_nil() )
653 SALOMEDS::SObject_var aMeshSO = ObjectToSObject( theStudy, theMesh );
654 if ( aMeshSO->_is_nil() ) {
655 aMeshSO = PublishInStudy( theStudy, SALOMEDS::SObject::_nil(), theMesh, "");
656 if ( aMeshSO->_is_nil())
657 return SALOMEDS::SObject::_nil();
659 int aType = (int)theGroup->GetType();
660 const char* aRootNames[] = {
661 "Compound Groups", "Groups of Nodes",
662 "Groups of Edges", "Groups of Faces", "Groups of Volumes" };
664 // Currently, groups with heterogenous content are not supported
665 if ( aType != SMESH::ALL ) {
666 long aRootTag = GetNodeGroupsTag() + aType - 1;
668 // Find or create groups root
669 SALOMEDS::SObject_var aRootSO = publish (theStudy, CORBA::Object::_nil(),
670 aMeshSO, aRootTag, 0, false );
672 SetName( aRootSO, aRootNames[aType] );
674 // Add new group to corresponding sub-tree
675 aGroupSO = publish (theStudy, theGroup, aRootSO, 0, "ICON_SMESH_TREE_GROUP" );
677 if ( aGroupSO->_is_nil() )
678 return aGroupSO._retn();
681 SetName( aGroupSO, theName, "Group" );
683 //Add reference to geometry
684 if ( !theShapeObject->_is_nil() )
685 addReference( theStudy, aGroupSO, theShapeObject, 1 );
687 return aGroupSO._retn();
690 //=======================================================================
691 //function : PublishHypothesis
693 //=======================================================================
695 SALOMEDS::SObject_ptr
696 SMESH_Gen_i::PublishHypothesis (SALOMEDS::Study_ptr theStudy,
697 SMESH::SMESH_Hypothesis_ptr theHyp,
700 if(MYDEBUG) MESSAGE("PublishHypothesis")
701 if (theStudy->_is_nil() || theHyp->_is_nil())
702 return SALOMEDS::SObject::_nil();
704 SALOMEDS::SObject_var aHypSO = ObjectToSObject( theStudy, theHyp );
705 if ( aHypSO->_is_nil() )
707 SALOMEDS::SComponent_var father = PublishComponent( theStudy );
708 if ( father->_is_nil() )
709 return aHypSO._retn();
711 //Find or Create Hypothesis root
712 bool isAlgo = ( !SMESH::SMESH_Algo::_narrow( theHyp )->_is_nil() );
713 int aRootTag = isAlgo ? GetAlgorithmsRootTag() : GetHypothesisRootTag();
714 SALOMEDS::SObject_var aRootSO =
715 publish (theStudy, CORBA::Object::_nil(),father, aRootTag,
716 isAlgo ? "ICON_SMESH_TREE_ALGO" : "ICON_SMESH_TREE_HYPO", false);
717 SetName( aRootSO, isAlgo ? "Algorithms" : "Hypotheses" );
719 // Add New Hypothesis
720 string aPmName = isAlgo ? "ICON_SMESH_TREE_ALGO_" : "ICON_SMESH_TREE_HYPO_";
721 aPmName += theHyp->GetName();
722 // prepend plugin name to pixmap name
723 string pluginName = myHypCreatorMap[string(theHyp->GetName())]->GetModuleName();
724 if ( pluginName != "StdMeshers" )
725 aPmName = pluginName + "::" + aPmName;
726 aHypSO = publish( theStudy, theHyp, aRootSO, 0, aPmName.c_str() );
729 if ( !aHypSO->_is_nil() ) {
730 CORBA::String_var aHypName = CORBA::string_dup( theHyp->GetName() );
731 SetName( aHypSO, theName, aHypName );
734 if(MYDEBUG) MESSAGE("PublishHypothesis--END")
735 return aHypSO._retn();
738 //=======================================================================
739 //function : GetMeshOrSubmeshByShape
741 //=======================================================================
743 SALOMEDS::SObject_ptr
744 SMESH_Gen_i::GetMeshOrSubmeshByShape (SALOMEDS::Study_ptr theStudy,
745 SMESH::SMESH_Mesh_ptr theMesh,
746 GEOM::GEOM_Object_ptr theShape)
748 if(MYDEBUG) MESSAGE("GetMeshOrSubmeshByShape")
749 SALOMEDS::SObject_var aMeshOrSubMesh;
750 if (theMesh->_is_nil() || ( theShape->_is_nil() && theMesh->HasShapeToMesh()))
751 return aMeshOrSubMesh._retn();
754 if(theMesh->HasShapeToMesh())
755 aShape = GeomObjectToShape( theShape );
757 aShape = SMESH_Mesh::PseudoShape();
759 SMESH_Mesh_i* mesh_i = objectToServant<SMESH_Mesh_i>( theMesh );
761 if ( !aShape.IsNull() && mesh_i && mesh_i->GetImpl().GetMeshDS() ) {
762 SMESHDS_Mesh* meshDS = mesh_i->GetImpl().GetMeshDS();
763 if ( aShape.IsSame( meshDS->ShapeToMesh() ))
764 aMeshOrSubMesh = ObjectToSObject( theStudy, theMesh );
766 int shapeID = meshDS->ShapeToIndex( aShape );
767 SMESH::SMESH_subMesh_var aSubMesh = mesh_i->getSubMesh(shapeID);
768 if ( !aSubMesh->_is_nil() )
769 aMeshOrSubMesh = ObjectToSObject( theStudy, aSubMesh );
772 if(MYDEBUG) MESSAGE("GetMeshOrSubmeshByShape--END")
773 return aMeshOrSubMesh._retn();
776 //=======================================================================
777 //function : AddHypothesisToShape
779 //=======================================================================
781 bool SMESH_Gen_i::AddHypothesisToShape(SALOMEDS::Study_ptr theStudy,
782 SMESH::SMESH_Mesh_ptr theMesh,
783 GEOM::GEOM_Object_ptr theShape,
784 SMESH::SMESH_Hypothesis_ptr theHyp)
786 if(MYDEBUG) MESSAGE("AddHypothesisToShape")
787 if (theStudy->_is_nil() || theMesh->_is_nil() ||
788 theHyp->_is_nil() || (theShape->_is_nil()
789 && theMesh->HasShapeToMesh()) )
792 SALOMEDS::SObject_var aMeshSO = ObjectToSObject( theStudy, theMesh );
793 if ( aMeshSO->_is_nil() )
794 aMeshSO = PublishMesh( theStudy, theMesh );
795 SALOMEDS::SObject_var aHypSO = PublishHypothesis( theStudy, theHyp );
796 if ( aMeshSO->_is_nil() || aHypSO->_is_nil())
799 // Find a mesh or submesh refering to theShape
800 SALOMEDS::SObject_var aMeshOrSubMesh =
801 GetMeshOrSubmeshByShape( theStudy, theMesh, theShape );
802 if ( aMeshOrSubMesh->_is_nil() )
805 TopoDS_Shape aShape = GeomObjectToShape( theShape );
806 SMESH_Mesh_i* mesh_i = objectToServant<SMESH_Mesh_i>( theMesh );
807 if ( !aShape.IsNull() && mesh_i && mesh_i->GetImpl().GetMeshDS() ) {
808 SMESHDS_Mesh* meshDS = mesh_i->GetImpl().GetMeshDS();
809 int shapeID = meshDS->ShapeToIndex( aShape );
810 SMESH::SMESH_subMesh_var aSubMesh = mesh_i->getSubMesh(shapeID);
811 aMeshOrSubMesh = PublishSubMesh( theStudy, theMesh, aSubMesh, theShape );
813 if ( aMeshOrSubMesh->_is_nil() )
817 //Find or Create Applied Hypothesis root
818 bool aIsAlgo = !SMESH::SMESH_Algo::_narrow( theHyp )->_is_nil();
819 SALOMEDS::SObject_var AHR =
820 publish (theStudy, CORBA::Object::_nil(), aMeshOrSubMesh,
821 aIsAlgo ? GetRefOnAppliedAlgorithmsTag() : GetRefOnAppliedHypothesisTag(),
822 aIsAlgo ? "ICON_SMESH_TREE_ALGO" : "ICON_SMESH_TREE_HYPO", false);
823 SetName( AHR, aIsAlgo ? "Applied algorithms" : "Applied hypotheses" );
824 if ( AHR->_is_nil() )
827 addReference( theStudy, AHR, theHyp );
828 if(MYDEBUG) MESSAGE("AddHypothesisToShape--END")
832 //=======================================================================
833 //function : RemoveHypothesisFromShape
835 //=======================================================================
837 bool SMESH_Gen_i::RemoveHypothesisFromShape(SALOMEDS::Study_ptr theStudy,
838 SMESH::SMESH_Mesh_ptr theMesh,
839 GEOM::GEOM_Object_ptr theShape,
840 SMESH::SMESH_Hypothesis_ptr theHyp)
842 if (theStudy->_is_nil() || theMesh->_is_nil() ||
843 theHyp->_is_nil() || (theShape->_is_nil()
844 && theMesh->HasShapeToMesh()))
847 SALOMEDS::SObject_var aHypSO = ObjectToSObject( theStudy, theHyp );
848 if ( aHypSO->_is_nil() )
851 // Find a mesh or submesh refering to theShape
852 SALOMEDS::SObject_var aMeshOrSubMesh =
853 GetMeshOrSubmeshByShape( theStudy, theMesh, theShape );
854 if ( aMeshOrSubMesh->_is_nil() )
857 // Find and remove a reference to aHypSO
858 SALOMEDS::SObject_var aRef, anObj;
859 CORBA::String_var anID = CORBA::string_dup( aHypSO->GetID() );
860 SALOMEDS::ChildIterator_var it = theStudy->NewChildIterator( aMeshOrSubMesh );
861 for ( it->InitEx( true ); it->More(); it->Next() ) {
863 if (anObj->ReferencedObject( aRef ) && strcmp( aRef->GetID(), anID ) == 0 ) {
864 theStudy->NewBuilder()->RemoveObject( anObj );
871 //=======================================================================
872 //function : UpdateSObject
874 //=======================================================================
875 void SMESH_Gen_i::UpdateParameters(CORBA::Object_ptr theObject, const char* theParameters)
879 cout<<"UpdateParameters : "<<theParameters<<endl;
880 SALOMEDS::Study_ptr aStudy = GetCurrentStudy();
881 if(aStudy->_is_nil() || CORBA::is_nil(theObject))
884 SALOMEDS::SObject_var aSObj = ObjectToSObject(aStudy,theObject);
888 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
890 SALOMEDS::GenericAttribute_var aFindAttr;
891 bool hasAttr = aSObj->FindAttribute(aFindAttr, "AttributeString");
893 cout<<"Find Attribute "<<hasAttr<<endl;
895 SALOMEDS::GenericAttribute_var anAttr;
896 anAttr = aStudyBuilder->FindOrCreateAttribute( aSObj, "AttributeString");
897 SALOMEDS::AttributeString_var aStringAttr = SALOMEDS::AttributeString::_narrow(anAttr);
899 TCollection_AsciiString aNewParams;
900 TCollection_AsciiString aOldParameters(aStringAttr->Value());
901 TCollection_AsciiString anInputParams(ParseParameters(theParameters));
904 aNewParams = anInputParams;
906 aNewParams = aOldParameters+"|"+anInputParams;
910 cout<<"Input Parameters : "<<anInputParams<<endl;
911 cout<<"Old Parameters : "<<aOldParameters<<endl;
912 cout<<"New Parameters : "<<aNewParams<<endl;
916 aStringAttr->SetValue( aNewParams.ToCString() );
919 //=======================================================================
920 //function : GetParameters
922 //=======================================================================
923 char* SMESH_Gen_i::ParseParameters(const char* theParameters)
925 const char* aParameters = CORBA::string_dup(theParameters);
926 TCollection_AsciiString anInputParams;
927 SALOMEDS::Study_ptr aStudy = GetCurrentStudy();
928 if( !aStudy->_is_nil() ) {
929 SALOMEDS::ListOfListOfStrings_var aSections = aStudy->ParseVariables(aParameters);
930 if(aSections->length() > 0) {
931 SALOMEDS::ListOfStrings aVars= aSections[0];
932 for(int i=0;i<aVars.length();i++ ) {
933 anInputParams += aStudy->IsVariable(aVars[i].in()) ?
934 TCollection_AsciiString(aVars[i].in()) : TCollection_AsciiString("");
935 if(i != aVars.length()-1)
940 return CORBA::string_dup(anInputParams.ToCString());
943 //=======================================================================
944 //function : GetParameters
946 //=======================================================================
947 char* SMESH_Gen_i::GetParameters(CORBA::Object_ptr theObject)
949 TCollection_AsciiString aResult;
951 SALOMEDS::Study_ptr aStudy = GetCurrentStudy();
952 SALOMEDS::SObject_var aSObj = ObjectToSObject(aStudy,theObject);
954 if(!aStudy->_is_nil() &&
955 !CORBA::is_nil(theObject) &&
958 SALOMEDS::GenericAttribute_var anAttr;
959 if ( aSObj->FindAttribute(anAttr, "AttributeString")) {
960 aResult = TCollection_AsciiString(SALOMEDS::AttributeString::_narrow(anAttr)->Value());
964 return CORBA::string_dup( aResult.ToCString() );