1 // Copyright (C) 2007-2011 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 // File : SMESH_Gen_i_1.cxx
23 // Created : Thu Oct 21 17:24:06 2004
24 // Author : Edward AGAPOV (eap)
28 #include "SMESH_Gen_i.hxx"
30 #include "SMESH_Mesh_i.hxx"
31 #include "SMESH_Hypothesis_i.hxx"
32 #include "SMESH_Algo_i.hxx"
33 #include "SMESH_Group_i.hxx"
34 #include "SMESH_subMesh_i.hxx"
36 #include CORBA_CLIENT_HEADER(SALOME_ModuleCatalog)
38 #include "utilities.h"
39 #include "Utils_ExceptHandlers.hxx"
41 #include <TCollection_AsciiString.hxx>
44 static int MYDEBUG = 0;
45 static int VARIABLE_DEBUG = 0;
47 static int MYDEBUG = 0;
48 static int VARIABLE_DEBUG = 0;
51 //=============================================================================
53 * Get...Tag [ static ]
55 * Methods which determine SMESH data model structure
57 //=============================================================================
59 long SMESH_Gen_i::GetHypothesisRootTag()
61 return SMESH::Tag_HypothesisRoot;
64 long SMESH_Gen_i::GetAlgorithmsRootTag()
66 return SMESH::Tag_AlgorithmsRoot;
69 long SMESH_Gen_i::GetRefOnShapeTag()
71 return SMESH::Tag_RefOnShape;
74 long SMESH_Gen_i::GetRefOnAppliedHypothesisTag()
76 return SMESH::Tag_RefOnAppliedHypothesis;
79 long SMESH_Gen_i::GetRefOnAppliedAlgorithmsTag()
81 return SMESH::Tag_RefOnAppliedAlgorithms;
84 long SMESH_Gen_i::GetSubMeshOnVertexTag()
86 return SMESH::Tag_SubMeshOnVertex;
89 long SMESH_Gen_i::GetSubMeshOnEdgeTag()
91 return SMESH::Tag_SubMeshOnEdge;
94 long SMESH_Gen_i::GetSubMeshOnFaceTag()
96 return SMESH::Tag_SubMeshOnFace;
99 long SMESH_Gen_i::GetSubMeshOnSolidTag()
101 return SMESH::Tag_SubMeshOnSolid;
104 long SMESH_Gen_i::GetSubMeshOnCompoundTag()
106 return SMESH::Tag_SubMeshOnCompound;
109 long SMESH_Gen_i::GetSubMeshOnWireTag()
111 return SMESH::Tag_SubMeshOnWire;
114 long SMESH_Gen_i::GetSubMeshOnShellTag()
116 return SMESH::Tag_SubMeshOnShell;
119 long SMESH_Gen_i::GetNodeGroupsTag()
121 return SMESH::Tag_NodeGroups;
124 long SMESH_Gen_i::GetEdgeGroupsTag()
126 return SMESH::Tag_EdgeGroups;
129 long SMESH_Gen_i::GetFaceGroupsTag()
131 return SMESH::Tag_FaceGroups;
134 long SMESH_Gen_i::GetVolumeGroupsTag()
136 return SMESH::Tag_VolumeGroups;
139 //=============================================================================
141 * SMESH_Gen_i::CanPublishInStudy
143 * Returns true if object can be published in the study
145 //=============================================================================
147 bool SMESH_Gen_i::CanPublishInStudy(CORBA::Object_ptr theIOR)
149 if(MYDEBUG) MESSAGE("CanPublishInStudy - "<<!CORBA::is_nil(myCurrentStudy));
150 if(CORBA::is_nil(myCurrentStudy))
153 SMESH::SMESH_Mesh_var aMesh = SMESH::SMESH_Mesh::_narrow(theIOR);
154 if( !aMesh->_is_nil() )
157 SMESH::SMESH_subMesh_var aSubMesh = SMESH::SMESH_subMesh::_narrow(theIOR);
158 if( !aSubMesh->_is_nil() )
161 SMESH::SMESH_Hypothesis_var aHyp = SMESH::SMESH_Hypothesis::_narrow(theIOR);
162 if( !aHyp->_is_nil() )
165 SMESH::SMESH_GroupBase_var aGroup = SMESH::SMESH_GroupBase::_narrow(theIOR);
166 if( !aGroup->_is_nil() )
169 if(MYDEBUG) MESSAGE("CanPublishInStudy--CANT");
173 //=======================================================================
174 //function : ObjectToSObject
176 //=======================================================================
178 SALOMEDS::SObject_ptr SMESH_Gen_i::ObjectToSObject(SALOMEDS::Study_ptr theStudy,
179 CORBA::Object_ptr theObject)
181 SALOMEDS::SObject_var aSO;
182 if ( !CORBA::is_nil( theStudy ) && !CORBA::is_nil( theObject ))
184 CORBA::String_var objStr = SMESH_Gen_i::GetORB()->object_to_string( theObject );
185 aSO = theStudy->FindObjectIOR( objStr.in() );
190 //=======================================================================
191 //function : objectToServant
193 //=======================================================================
195 template<typename T> static inline T* objectToServant( CORBA::Object_ptr theIOR )
197 return dynamic_cast<T*>( SMESH_Gen_i::GetServant( theIOR ).in() );
200 //=======================================================================
201 //function : ShapeToGeomObject
203 //=======================================================================
205 GEOM::GEOM_Object_ptr SMESH_Gen_i::ShapeToGeomObject (const TopoDS_Shape& theShape )
207 GEOM::GEOM_Object_var aShapeObj;
208 if ( !theShape.IsNull() ) {
209 GEOM_Client* aClient = GetShapeReader();
210 TCollection_AsciiString IOR;
211 if ( aClient && aClient->Find( theShape, IOR ))
213 CORBA::Object_var obj = GetORB()->string_to_object( IOR.ToCString() );
214 aShapeObj = GEOM::GEOM_Object::_narrow ( obj );
217 return aShapeObj._retn();
220 //=======================================================================
221 //function : GeomObjectToShape
223 //=======================================================================
225 TopoDS_Shape SMESH_Gen_i::GeomObjectToShape(GEOM::GEOM_Object_ptr theGeomObject)
228 if ( !theGeomObject->_is_nil() ) {
229 GEOM_Client* aClient = GetShapeReader();
230 GEOM::GEOM_Gen_ptr aGeomEngine = GetGeomEngine();
231 if ( aClient && !aGeomEngine->_is_nil () )
232 S = aClient->GetShape( aGeomEngine, theGeomObject );
237 //=======================================================================
240 //=======================================================================
242 static SALOMEDS::SObject_ptr publish(SALOMEDS::Study_ptr theStudy,
243 CORBA::Object_ptr theIOR,
244 SALOMEDS::SObject_ptr theFatherObject,
245 const int theTag = 0,
246 const char* thePixMap = 0,
247 const bool theSelectable = true)
249 SALOMEDS::SObject_var SO = SMESH_Gen_i::ObjectToSObject( theStudy, theIOR );
250 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
251 if ( SO->_is_nil() ) {
253 SO = aStudyBuilder->NewObject( theFatherObject );
254 else if ( !theFatherObject->FindSubObject( theTag, SO ))
255 SO = aStudyBuilder->NewObjectToTag( theFatherObject, theTag );
258 SALOMEDS::GenericAttribute_var anAttr;
259 if ( !CORBA::is_nil( theIOR )) {
260 anAttr = aStudyBuilder->FindOrCreateAttribute( SO, "AttributeIOR" );
261 CORBA::String_var objStr = SMESH_Gen_i::GetORB()->object_to_string( theIOR );
262 SALOMEDS::AttributeIOR::_narrow(anAttr)->SetValue( objStr.in() );
265 anAttr = aStudyBuilder->FindOrCreateAttribute( SO, "AttributePixMap" );
266 SALOMEDS::AttributePixMap_var pm = SALOMEDS::AttributePixMap::_narrow( anAttr );
267 pm->SetPixMap( thePixMap );
269 if ( !theSelectable ) {
270 anAttr = aStudyBuilder->FindOrCreateAttribute( SO, "AttributeSelectable" );
271 SALOMEDS::AttributeSelectable::_narrow( anAttr )->SetSelectable( false );
276 //=======================================================================
279 //=======================================================================
281 void SMESH_Gen_i::SetName(SALOMEDS::SObject_ptr theSObject,
283 const char* theDefaultName)
285 if ( !theSObject->_is_nil() ) {
286 SALOMEDS::StudyBuilder_var aStudyBuilder = theSObject->GetStudy()->NewBuilder();
287 SALOMEDS::GenericAttribute_var anAttr =
288 aStudyBuilder->FindOrCreateAttribute( theSObject, "AttributeName" );
289 SALOMEDS::AttributeName_var aNameAttr = SALOMEDS::AttributeName::_narrow( anAttr );
290 if ( theName && strlen( theName ) != 0 )
291 aNameAttr->SetValue( theName );
293 CORBA::String_var curName = CORBA::string_dup( aNameAttr->Value() );
294 if ( strlen( curName ) == 0 ) {
295 TCollection_AsciiString aName( (char*) theDefaultName );
296 aName += TCollection_AsciiString("_") + TCollection_AsciiString( theSObject->Tag() );
297 aNameAttr->SetValue( aName.ToCString() );
303 //=======================================================================
304 //function : SetPixMap
306 //=======================================================================
308 void SMESH_Gen_i::SetPixMap(SALOMEDS::SObject_ptr theSObject,
309 const char* thePixMap)
311 if ( !theSObject->_is_nil() && thePixMap && strlen( thePixMap ))
313 SALOMEDS::Study_var aStudy = theSObject->GetStudy();
314 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
315 SALOMEDS::GenericAttribute_var anAttr =
316 aStudyBuilder->FindOrCreateAttribute( theSObject, "AttributePixMap" );
317 SALOMEDS::AttributePixMap_var aPMAttr = SALOMEDS::AttributePixMap::_narrow( anAttr );
318 aPMAttr->SetPixMap( thePixMap );
322 //=======================================================================
323 //function : addReference
325 //=======================================================================
327 static void addReference (SALOMEDS::Study_ptr theStudy,
328 SALOMEDS::SObject_ptr theSObject,
329 CORBA::Object_ptr theToObject,
332 SALOMEDS::SObject_var aToObjSO = SMESH_Gen_i::ObjectToSObject( theStudy, theToObject );
333 if ( !aToObjSO->_is_nil() && !theSObject->_is_nil() ) {
334 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
335 SALOMEDS::SObject_var aReferenceSO;
337 // check if the reference to theToObject already exists
338 // and find a free label for the reference object
339 bool isReferred = false;
341 SALOMEDS::ChildIterator_var anIter = theStudy->NewChildIterator( theSObject );
342 for ( ; !isReferred && anIter->More(); anIter->Next(), ++tag ) {
343 if ( anIter->Value()->ReferencedObject( aReferenceSO )) {
344 if ( strcmp( aReferenceSO->GetID(), aToObjSO->GetID() ) == 0 )
347 else if ( !theTag ) {
348 SALOMEDS::GenericAttribute_var anAttr;
349 if ( !anIter->Value()->FindAttribute( anAttr, "AttributeIOR" ))
358 if ( !theSObject->FindSubObject( theTag, aReferenceSO ))
359 aReferenceSO = aStudyBuilder->NewObjectToTag( theSObject, theTag );
360 aStudyBuilder->Addreference( aReferenceSO, aToObjSO );
364 //=============================================================================
366 * SMESH_Gen_i::PublishInStudy
368 * Publish object in the study
370 //=============================================================================
372 SALOMEDS::SObject_ptr SMESH_Gen_i::PublishInStudy(SALOMEDS::Study_ptr theStudy,
373 SALOMEDS::SObject_ptr theSObject,
374 CORBA::Object_ptr theIOR,
376 throw (SALOME::SALOME_Exception)
378 Unexpect aCatch(SALOME_SalomeException);
379 SALOMEDS::SObject_var aSO;
380 if ( CORBA::is_nil( theStudy ) || CORBA::is_nil( theIOR ))
382 if(MYDEBUG) MESSAGE("PublishInStudy");
385 SMESH::SMESH_Mesh_var aMesh = SMESH::SMESH_Mesh::_narrow( theIOR );
386 if( !aMesh->_is_nil() )
387 aSO = PublishMesh( theStudy, aMesh, theName );
389 // Publishing a sub-mesh
390 SMESH::SMESH_subMesh_var aSubMesh = SMESH::SMESH_subMesh::_narrow( theIOR );
391 if( aSO->_is_nil() && !aSubMesh->_is_nil() ) {
392 GEOM::GEOM_Object_var aShapeObject = aSubMesh->GetSubShape();
393 aMesh = aSubMesh->GetFather();
394 aSO = PublishSubMesh( theStudy, aMesh, aSubMesh, aShapeObject, theName );
397 // Publishing a hypothesis or algorithm
398 SMESH::SMESH_Hypothesis_var aHyp = SMESH::SMESH_Hypothesis::_narrow( theIOR );
399 if ( aSO->_is_nil() && !aHyp->_is_nil() )
400 aSO = PublishHypothesis( theStudy, aHyp );
402 // Publishing a group
403 SMESH::SMESH_GroupBase_var aGroup = SMESH::SMESH_GroupBase::_narrow(theIOR);
404 if ( aSO->_is_nil() && !aGroup->_is_nil() ) {
405 GEOM::GEOM_Object_var aShapeObject;
406 aMesh = aGroup->GetMesh();
407 aSO = PublishGroup( theStudy, aMesh, aGroup, aShapeObject, theName );
409 if(MYDEBUG) MESSAGE("PublishInStudy_END");
414 //=======================================================================
415 //function : PublishComponent
417 //=======================================================================
419 SALOMEDS::SComponent_ptr SMESH_Gen_i::PublishComponent(SALOMEDS::Study_ptr theStudy)
421 if ( CORBA::is_nil( theStudy ))
422 return SALOMEDS::SComponent::_nil();
423 if(MYDEBUG) MESSAGE("PublishComponent");
425 SALOMEDS::SComponent_var father =
426 SALOMEDS::SComponent::_narrow( theStudy->FindComponent( ComponentDataType() ) );
427 if ( !CORBA::is_nil( father ) )
428 return father._retn();
430 SALOME_ModuleCatalog::ModuleCatalog_var aCat =
431 SALOME_ModuleCatalog::ModuleCatalog::_narrow( GetNS()->Resolve("/Kernel/ModulCatalog") );
432 if ( CORBA::is_nil( aCat ) )
433 return father._retn();
435 SALOME_ModuleCatalog::Acomponent_var aComp = aCat->GetComponent( ComponentDataType() );
436 if ( CORBA::is_nil( aComp ) )
437 return father._retn();
439 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
440 SALOMEDS::GenericAttribute_var anAttr;
441 SALOMEDS::AttributePixMap_var aPixmap;
443 father = aStudyBuilder->NewComponent( ComponentDataType() );
444 aStudyBuilder->DefineComponentInstance( father, SMESH_Gen::_this() );
445 anAttr = aStudyBuilder->FindOrCreateAttribute( father, "AttributePixMap" );
446 aPixmap = SALOMEDS::AttributePixMap::_narrow( anAttr );
447 aPixmap ->SetPixMap( "ICON_OBJBROWSER_SMESH" );
448 SetName( father, aComp->componentusername(), "MESH" );
449 if(MYDEBUG) MESSAGE("PublishComponent--END");
451 return father._retn();
454 //=============================================================================
456 * findMaxChildTag [ static internal ]
458 * Finds maximum child tag for the given object
460 //=============================================================================
462 static long findMaxChildTag( SALOMEDS::SObject_ptr theSObject )
465 if ( !theSObject->_is_nil() ) {
466 SALOMEDS::Study_var aStudy = theSObject->GetStudy();
467 if ( !aStudy->_is_nil() ) {
468 SALOMEDS::ChildIterator_var anIter = aStudy->NewChildIterator( theSObject );
469 for ( ; anIter->More(); anIter->Next() ) {
470 long nTag = anIter->Value()->Tag();
479 //=======================================================================
480 //function : PublishMesh
482 //=======================================================================
484 SALOMEDS::SObject_ptr SMESH_Gen_i::PublishMesh (SALOMEDS::Study_ptr theStudy,
485 SMESH::SMESH_Mesh_ptr theMesh,
488 if ( CORBA::is_nil( theStudy ) ||
489 CORBA::is_nil( theMesh ))
490 return SALOMEDS::SComponent::_nil();
491 if(MYDEBUG) MESSAGE("PublishMesh--IN");
493 // find or publish a mesh
495 SALOMEDS::SObject_var aMeshSO = ObjectToSObject( theStudy, theMesh );
496 if ( aMeshSO->_is_nil() )
498 SALOMEDS::SComponent_var father = PublishComponent( theStudy );
499 if ( father->_is_nil() )
500 return aMeshSO._retn();
502 // Find correct free tag
503 long aTag = findMaxChildTag( father.in() );
504 if ( aTag <= GetAlgorithmsRootTag() )
505 aTag = GetAlgorithmsRootTag() + 1;
509 aMeshSO = publish (theStudy, theMesh, father, aTag, "ICON_SMESH_TREE_MESH_WARN" );
510 if ( aMeshSO->_is_nil() )
511 return aMeshSO._retn();
513 SetName( aMeshSO, theName, "Mesh" );
515 // Add shape reference
517 GEOM::GEOM_Object_var aShapeObject = theMesh->GetShapeToMesh();
518 if ( !CORBA::is_nil( aShapeObject )) {
519 addReference( theStudy, aMeshSO, aShapeObject, GetRefOnShapeTag() );
521 // Publish global hypotheses
523 SMESH::ListOfHypothesis_var hypList = theMesh->GetHypothesisList( aShapeObject );
524 for ( int i = 0; i < hypList->length(); i++ ) {
525 SMESH::SMESH_Hypothesis_var aHyp = SMESH::SMESH_Hypothesis::_narrow( hypList[ i ]);
526 PublishHypothesis( theStudy, aHyp );
527 AddHypothesisToShape( theStudy, theMesh, aShapeObject, aHyp );
533 SMESH_Mesh_i* mesh_i = objectToServant<SMESH_Mesh_i>( theMesh );
535 return aMeshSO._retn();
536 map<int, SMESH_subMesh_i*>& subMap = mesh_i->_mapSubMesh_i;
537 map<int, SMESH_subMesh_i*>::iterator subIt = subMap.begin();
538 for ( ; subIt != subMap.end(); subIt++ ) {
539 SMESH::SMESH_subMesh_ptr aSubMesh = (*subIt).second->_this();
540 if ( !CORBA::is_nil( aSubMesh )) {
541 aShapeObject = aSubMesh->GetSubShape();
542 PublishSubMesh( theStudy, theMesh, aSubMesh, aShapeObject );
547 const map<int, SMESH::SMESH_GroupBase_ptr>& grMap = mesh_i->getGroups();
548 map<int, SMESH::SMESH_GroupBase_ptr>::const_iterator it = grMap.begin();
549 for ( ; it != grMap.end(); it++ )
551 SMESH::SMESH_GroupBase_ptr aGroup = (*it).second;
552 if ( !aGroup->_is_nil() ) {
553 GEOM::GEOM_Object_var aShapeObj;
554 SMESH::SMESH_GroupOnGeom_var aGeomGroup =
555 SMESH::SMESH_GroupOnGeom::_narrow( aGroup );
556 if ( !aGeomGroup->_is_nil() )
557 aShapeObj = aGeomGroup->GetShape();
558 PublishGroup( theStudy, theMesh, aGroup, aShapeObj );
562 if(MYDEBUG) MESSAGE("PublishMesh_END");
563 return aMeshSO._retn();
566 //=======================================================================
567 //function : PublishSubMesh
569 //=======================================================================
571 SALOMEDS::SObject_ptr SMESH_Gen_i::PublishSubMesh (SALOMEDS::Study_ptr theStudy,
572 SMESH::SMESH_Mesh_ptr theMesh,
573 SMESH::SMESH_subMesh_ptr theSubMesh,
574 GEOM::GEOM_Object_ptr theShapeObject,
577 if (theStudy->_is_nil() || theMesh->_is_nil() ||
578 theSubMesh->_is_nil() || theShapeObject->_is_nil() )
579 return SALOMEDS::SObject::_nil();
581 SALOMEDS::SObject_var aSubMeshSO = ObjectToSObject( theStudy, theSubMesh );
582 if ( aSubMeshSO->_is_nil() )
584 SALOMEDS::SObject_var aMeshSO = ObjectToSObject( theStudy, theMesh );
585 if ( aMeshSO->_is_nil() ) {
586 aMeshSO = PublishMesh( theStudy, theMesh );
587 if ( aMeshSO->_is_nil())
588 return SALOMEDS::SObject::_nil();
590 // Find submesh sub-tree tag
592 const char* aRootName = "";
593 switch ( theShapeObject->GetShapeType() ) {
595 aRootTag = GetSubMeshOnVertexTag();
596 aRootName = "SubMeshes on Vertex";
599 aRootTag = GetSubMeshOnEdgeTag();
600 aRootName = "SubMeshes on Edge";
603 aRootTag = GetSubMeshOnWireTag();
604 aRootName = "SubMeshes on Wire";
607 aRootTag = GetSubMeshOnFaceTag();
608 aRootName = "SubMeshes on Face";
611 aRootTag = GetSubMeshOnShellTag();
612 aRootName = "SubMeshes on Shell";
615 aRootTag = GetSubMeshOnSolidTag();
616 aRootName = "SubMeshes on Solid";
619 aRootTag = GetSubMeshOnCompoundTag();
620 aRootName = "SubMeshes on Compound";
624 // Find or create submesh root
625 SALOMEDS::SObject_var aRootSO = publish (theStudy, CORBA::Object::_nil(),
626 aMeshSO, aRootTag, 0, false );
627 SetName( aRootSO, aRootName );
629 // Add new submesh to corresponding sub-tree
630 aSubMeshSO = publish (theStudy, theSubMesh, aRootSO, 0, "ICON_SMESH_TREE_MESH_WARN");
631 if ( aSubMeshSO->_is_nil() )
632 return aSubMeshSO._retn();
634 SetName( aSubMeshSO, theName, "SubMesh" );
636 // Add reference to theShapeObject
638 addReference( theStudy, aSubMeshSO, theShapeObject, 1 );
640 // Publish hypothesis
642 SMESH::ListOfHypothesis * hypList = theMesh->GetHypothesisList( theShapeObject );
644 for ( int i = 0; i < hypList->length(); i++ ) {
645 SMESH::SMESH_Hypothesis_var aHyp = SMESH::SMESH_Hypothesis::_narrow( (*hypList)[ i ]);
646 PublishHypothesis( theStudy, aHyp );
647 AddHypothesisToShape( theStudy, theMesh, theShapeObject, aHyp );
650 return aSubMeshSO._retn();
653 //=======================================================================
654 //function : PublishGroup
656 //=======================================================================
658 SALOMEDS::SObject_ptr SMESH_Gen_i::PublishGroup (SALOMEDS::Study_ptr theStudy,
659 SMESH::SMESH_Mesh_ptr theMesh,
660 SMESH::SMESH_GroupBase_ptr theGroup,
661 GEOM::GEOM_Object_ptr theShapeObject,
664 if (theStudy->_is_nil() || theMesh->_is_nil() || theGroup->_is_nil() )
665 return SALOMEDS::SObject::_nil();
667 SALOMEDS::SObject_var aGroupSO = ObjectToSObject( theStudy, theGroup );
668 if ( aGroupSO->_is_nil() )
670 SALOMEDS::SObject_var aMeshSO = ObjectToSObject( theStudy, theMesh );
671 if ( aMeshSO->_is_nil() ) {
672 aMeshSO = PublishInStudy( theStudy, SALOMEDS::SObject::_nil(), theMesh, "");
673 if ( aMeshSO->_is_nil())
674 return SALOMEDS::SObject::_nil();
676 int aType = (int)theGroup->GetType();
677 const char* aRootNames[] = {
678 "Compound Groups", "Groups of Nodes", "Groups of Edges",
679 "Groups of Faces", "Groups of Volumes", "Groups of 0D Elements" };
681 // Currently, groups with heterogenous content are not supported
682 if ( aType != SMESH::ALL ) {
683 long aRootTag = GetNodeGroupsTag() + aType - 1;
685 // Find or create groups root
686 SALOMEDS::SObject_var aRootSO = publish (theStudy, CORBA::Object::_nil(),
687 aMeshSO, aRootTag, 0, false );
689 SetName( aRootSO, aRootNames[aType] );
691 // Add new group to corresponding sub-tree
692 aGroupSO = publish (theStudy, theGroup, aRootSO, 0, "ICON_SMESH_TREE_GROUP" );
694 if ( aGroupSO->_is_nil() )
695 return aGroupSO._retn();
698 SetName( aGroupSO, theName, "Group" );
700 //Add reference to geometry
701 if ( !theShapeObject->_is_nil() )
702 addReference( theStudy, aGroupSO, theShapeObject, 1 );
704 return aGroupSO._retn();
707 //=======================================================================
708 //function : PublishHypothesis
710 //=======================================================================
712 SALOMEDS::SObject_ptr
713 SMESH_Gen_i::PublishHypothesis (SALOMEDS::Study_ptr theStudy,
714 SMESH::SMESH_Hypothesis_ptr theHyp,
717 if(MYDEBUG) MESSAGE("PublishHypothesis")
718 if (theStudy->_is_nil() || theHyp->_is_nil())
719 return SALOMEDS::SObject::_nil();
721 SALOMEDS::SObject_var aHypSO = ObjectToSObject( theStudy, theHyp );
722 if ( aHypSO->_is_nil() )
724 SALOMEDS::SComponent_var father = PublishComponent( theStudy );
725 if ( father->_is_nil() )
726 return aHypSO._retn();
728 //Find or Create Hypothesis root
729 bool isAlgo = ( !SMESH::SMESH_Algo::_narrow( theHyp )->_is_nil() );
730 int aRootTag = isAlgo ? GetAlgorithmsRootTag() : GetHypothesisRootTag();
731 SALOMEDS::SObject_var aRootSO =
732 publish (theStudy, CORBA::Object::_nil(),father, aRootTag,
733 isAlgo ? "ICON_SMESH_TREE_ALGO" : "ICON_SMESH_TREE_HYPO", false);
734 SetName( aRootSO, isAlgo ? "Algorithms" : "Hypotheses" );
736 // Add New Hypothesis
737 string aPmName = isAlgo ? "ICON_SMESH_TREE_ALGO_" : "ICON_SMESH_TREE_HYPO_";
738 aPmName += theHyp->GetName();
739 // prepend plugin name to pixmap name
740 string pluginName = myHypCreatorMap[string(theHyp->GetName())]->GetModuleName();
741 if ( pluginName != "StdMeshers" )
742 aPmName = pluginName + "::" + aPmName;
743 aHypSO = publish( theStudy, theHyp, aRootSO, 0, aPmName.c_str() );
746 if ( !aHypSO->_is_nil() ) {
747 CORBA::String_var aHypName = CORBA::string_dup( theHyp->GetName() );
748 SetName( aHypSO, theName, aHypName );
751 if(MYDEBUG) MESSAGE("PublishHypothesis--END")
752 return aHypSO._retn();
755 //=======================================================================
756 //function : GetMeshOrSubmeshByShape
758 //=======================================================================
760 SALOMEDS::SObject_ptr
761 SMESH_Gen_i::GetMeshOrSubmeshByShape (SALOMEDS::Study_ptr theStudy,
762 SMESH::SMESH_Mesh_ptr theMesh,
763 GEOM::GEOM_Object_ptr theShape)
765 if(MYDEBUG) MESSAGE("GetMeshOrSubmeshByShape")
766 SALOMEDS::SObject_var aMeshOrSubMesh;
767 if (theMesh->_is_nil() || ( theShape->_is_nil() && theMesh->HasShapeToMesh()))
768 return aMeshOrSubMesh._retn();
771 if(theMesh->HasShapeToMesh())
772 aShape = GeomObjectToShape( theShape );
774 aShape = SMESH_Mesh::PseudoShape();
776 SMESH_Mesh_i* mesh_i = objectToServant<SMESH_Mesh_i>( theMesh );
778 if ( !aShape.IsNull() && mesh_i && mesh_i->GetImpl().GetMeshDS() ) {
779 SMESHDS_Mesh* meshDS = mesh_i->GetImpl().GetMeshDS();
780 if ( aShape.IsSame( meshDS->ShapeToMesh() ))
781 aMeshOrSubMesh = ObjectToSObject( theStudy, theMesh );
783 int shapeID = meshDS->ShapeToIndex( aShape );
784 SMESH::SMESH_subMesh_var aSubMesh = mesh_i->getSubMesh(shapeID);
785 if ( !aSubMesh->_is_nil() )
786 aMeshOrSubMesh = ObjectToSObject( theStudy, aSubMesh );
789 if(MYDEBUG) MESSAGE("GetMeshOrSubmeshByShape--END")
790 return aMeshOrSubMesh._retn();
793 //=======================================================================
794 //function : AddHypothesisToShape
796 //=======================================================================
798 bool SMESH_Gen_i::AddHypothesisToShape(SALOMEDS::Study_ptr theStudy,
799 SMESH::SMESH_Mesh_ptr theMesh,
800 GEOM::GEOM_Object_ptr theShape,
801 SMESH::SMESH_Hypothesis_ptr theHyp)
803 if(MYDEBUG) MESSAGE("AddHypothesisToShape")
804 if (theStudy->_is_nil() || theMesh->_is_nil() ||
805 theHyp->_is_nil() || (theShape->_is_nil()
806 && theMesh->HasShapeToMesh()) )
809 SALOMEDS::SObject_var aMeshSO = ObjectToSObject( theStudy, theMesh );
810 if ( aMeshSO->_is_nil() )
811 aMeshSO = PublishMesh( theStudy, theMesh );
812 SALOMEDS::SObject_var aHypSO = PublishHypothesis( theStudy, theHyp );
813 if ( aMeshSO->_is_nil() || aHypSO->_is_nil())
816 // Find a mesh or submesh refering to theShape
817 SALOMEDS::SObject_var aMeshOrSubMesh =
818 GetMeshOrSubmeshByShape( theStudy, theMesh, theShape );
819 if ( aMeshOrSubMesh->_is_nil() )
822 TopoDS_Shape aShape = GeomObjectToShape( theShape );
823 SMESH_Mesh_i* mesh_i = objectToServant<SMESH_Mesh_i>( theMesh );
824 if ( !aShape.IsNull() && mesh_i && mesh_i->GetImpl().GetMeshDS() ) {
825 SMESHDS_Mesh* meshDS = mesh_i->GetImpl().GetMeshDS();
826 int shapeID = meshDS->ShapeToIndex( aShape );
827 SMESH::SMESH_subMesh_var aSubMesh = mesh_i->getSubMesh(shapeID);
828 aMeshOrSubMesh = PublishSubMesh( theStudy, theMesh, aSubMesh, theShape );
830 if ( aMeshOrSubMesh->_is_nil() )
834 //Find or Create Applied Hypothesis root
835 bool aIsAlgo = !SMESH::SMESH_Algo::_narrow( theHyp )->_is_nil();
836 SALOMEDS::SObject_var AHR =
837 publish (theStudy, CORBA::Object::_nil(), aMeshOrSubMesh,
838 aIsAlgo ? GetRefOnAppliedAlgorithmsTag() : GetRefOnAppliedHypothesisTag(),
839 aIsAlgo ? "ICON_SMESH_TREE_ALGO" : "ICON_SMESH_TREE_HYPO", false);
840 SetName( AHR, aIsAlgo ? "Applied algorithms" : "Applied hypotheses" );
841 if ( AHR->_is_nil() )
844 addReference( theStudy, AHR, theHyp );
845 if(MYDEBUG) MESSAGE("AddHypothesisToShape--END")
849 //=======================================================================
850 //function : RemoveHypothesisFromShape
852 //=======================================================================
854 bool SMESH_Gen_i::RemoveHypothesisFromShape(SALOMEDS::Study_ptr theStudy,
855 SMESH::SMESH_Mesh_ptr theMesh,
856 GEOM::GEOM_Object_ptr theShape,
857 SMESH::SMESH_Hypothesis_ptr theHyp)
859 if (theStudy->_is_nil() || theMesh->_is_nil() ||
860 theHyp->_is_nil() || (theShape->_is_nil()
861 && theMesh->HasShapeToMesh()))
864 SALOMEDS::SObject_var aHypSO = ObjectToSObject( theStudy, theHyp );
865 if ( aHypSO->_is_nil() )
868 // Find a mesh or submesh refering to theShape
869 SALOMEDS::SObject_var aMeshOrSubMesh =
870 GetMeshOrSubmeshByShape( theStudy, theMesh, theShape );
871 if ( aMeshOrSubMesh->_is_nil() )
874 // Find and remove a reference to aHypSO
875 SALOMEDS::SObject_var aRef, anObj;
876 CORBA::String_var anID = CORBA::string_dup( aHypSO->GetID() );
877 SALOMEDS::ChildIterator_var it = theStudy->NewChildIterator( aMeshOrSubMesh );
878 for ( it->InitEx( true ); it->More(); it->Next() ) {
880 if (anObj->ReferencedObject( aRef ) && strcmp( aRef->GetID(), anID ) == 0 ) {
881 theStudy->NewBuilder()->RemoveObject( anObj );
888 //=======================================================================
889 //function : UpdateParameters
891 //=======================================================================
892 void SMESH_Gen_i::UpdateParameters(CORBA::Object_ptr theObject, const char* theParameters)
896 cout<<"UpdateParameters : "<<theParameters<<endl;
897 SALOMEDS::Study_ptr aStudy = GetCurrentStudy();
898 if(aStudy->_is_nil() || CORBA::is_nil(theObject))
901 SALOMEDS::SObject_var aSObj = ObjectToSObject(aStudy,theObject);
905 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
907 SALOMEDS::GenericAttribute_var aFindAttr;
908 bool hasAttr = aSObj->FindAttribute(aFindAttr, "AttributeString");
910 cout<<"Find Attribute "<<hasAttr<<endl;
912 SALOMEDS::GenericAttribute_var anAttr;
913 anAttr = aStudyBuilder->FindOrCreateAttribute( aSObj, "AttributeString");
914 SALOMEDS::AttributeString_var aStringAttr = SALOMEDS::AttributeString::_narrow(anAttr);
916 CORBA::String_var oldparVar = aStringAttr->Value();
917 CORBA::String_var inpparVar = ParseParameters(theParameters);
918 TCollection_AsciiString aNewParams;
919 TCollection_AsciiString aOldParameters(oldparVar.inout());
920 TCollection_AsciiString anInputParams(inpparVar.inout());
922 aNewParams = anInputParams;
925 int pos = aOldParameters.SearchFromEnd("|");
927 TCollection_AsciiString previousParamFull(aOldParameters.Split(pos));
928 TCollection_AsciiString previousParam(previousParamFull);
929 TCollection_AsciiString theRepet("1");
930 pos = previousParam.SearchFromEnd(";*=");
933 theRepet = previousParam.Split(pos+2);
936 previousParam.Split(pos);
938 if(previousParam == anInputParams)
940 theRepet = theRepet.IntegerValue()+1;
941 aNewParams = aOldParameters + previousParam + ";*=" + theRepet;
945 aNewParams = aOldParameters + previousParamFull + "|" + anInputParams;
951 cout<<"Input Parameters : "<<anInputParams<<endl;
952 cout<<"Old Parameters : "<<aOldParameters<<endl;
953 cout<<"New Parameters : "<<aNewParams<<endl;
956 aStringAttr->SetValue( aNewParams.ToCString() );
959 //=======================================================================
960 //function : ParseParameters
962 //=======================================================================
963 char* SMESH_Gen_i::ParseParameters(const char* theParameters)
965 //const char* aParameters = theParameters;
966 // const char* aParameters = CORBA::string_dup(theParameters);
967 TCollection_AsciiString anInputParams;
968 SALOMEDS::Study_var aStudy = GetCurrentStudy();
969 if( !aStudy->_is_nil() ) {
970 // SALOMEDS::ListOfListOfStrings_var aSections = aStudy->ParseVariables(theParameters);
971 // for(int j=0;j<aSections->length();j++) {
972 // SALOMEDS::ListOfStrings aVars= aSections[j];
973 // for(int i=0;i<aVars.length();i++ ) {
974 // anInputParams += aStudy->IsVariable(aVars[i].in()) ?
975 // TCollection_AsciiString(aVars[i].in()) : TCollection_AsciiString("");
976 // if(i != aVars.length()-1)
977 // anInputParams+=":";
979 // if(j!=aSections->length()-1)
980 // anInputParams+="|";
982 TCollection_AsciiString paramStr( theParameters );
983 static TCollection_AsciiString separators(":|");
985 char sep, *pParams = (char*)paramStr.ToCString();
986 while ( beg < paramStr.Length() )
989 while ( ++end < paramStr.Length() )
990 if ( pParams[end] == ':' || pParams[end] == '|')
992 if ( end < paramStr.Length())
997 if ( aStudy->IsVariable( pParams+beg ))
998 anInputParams += pParams+beg;
999 if ( end < paramStr.Length() )
1000 anInputParams += sep;
1006 return CORBA::string_dup(anInputParams.ToCString());
1009 //=======================================================================
1010 //function : GetParameters
1012 //=======================================================================
1013 char* SMESH_Gen_i::GetParameters(CORBA::Object_ptr theObject)
1015 TCollection_AsciiString aResult;
1017 SALOMEDS::Study_ptr aStudy = GetCurrentStudy();
1018 SALOMEDS::SObject_var aSObj = ObjectToSObject(aStudy,theObject);
1020 if(!aStudy->_is_nil() &&
1021 !CORBA::is_nil(theObject) &&
1024 SALOMEDS::GenericAttribute_var anAttr;
1025 if ( aSObj->FindAttribute(anAttr, "AttributeString")) {
1026 aResult = TCollection_AsciiString(SALOMEDS::AttributeString::_narrow(anAttr)->Value());
1030 return CORBA::string_dup( aResult.ToCString() );