1 // Copyright (C) 2007-2010 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
24 // File : SMESH_Gen_i_1.cxx
25 // Created : Thu Oct 21 17:24:06 2004
26 // Author : Edward AGAPOV (eap)
30 #include "SMESH_Gen_i.hxx"
32 #include "SMESH_Mesh_i.hxx"
33 #include "SMESH_Hypothesis_i.hxx"
34 #include "SMESH_Algo_i.hxx"
35 #include "SMESH_Group_i.hxx"
36 #include "SMESH_subMesh_i.hxx"
38 #include CORBA_CLIENT_HEADER(SALOME_ModuleCatalog)
40 #include "utilities.h"
41 #include "Utils_ExceptHandlers.hxx"
43 #include <TCollection_AsciiString.hxx>
46 static int MYDEBUG = 0;
47 static int VARIABLE_DEBUG = 0;
49 static int MYDEBUG = 0;
50 static int VARIABLE_DEBUG = 0;
53 //=============================================================================
55 * Get...Tag [ static ]
57 * Methods which determine SMESH data model structure
59 //=============================================================================
61 long SMESH_Gen_i::GetHypothesisRootTag()
63 return SMESH::Tag_HypothesisRoot;
66 long SMESH_Gen_i::GetAlgorithmsRootTag()
68 return SMESH::Tag_AlgorithmsRoot;
71 long SMESH_Gen_i::GetRefOnShapeTag()
73 return SMESH::Tag_RefOnShape;
76 long SMESH_Gen_i::GetRefOnAppliedHypothesisTag()
78 return SMESH::Tag_RefOnAppliedHypothesis;
81 long SMESH_Gen_i::GetRefOnAppliedAlgorithmsTag()
83 return SMESH::Tag_RefOnAppliedAlgorithms;
86 long SMESH_Gen_i::GetSubMeshOnVertexTag()
88 return SMESH::Tag_SubMeshOnVertex;
91 long SMESH_Gen_i::GetSubMeshOnEdgeTag()
93 return SMESH::Tag_SubMeshOnEdge;
96 long SMESH_Gen_i::GetSubMeshOnFaceTag()
98 return SMESH::Tag_SubMeshOnFace;
101 long SMESH_Gen_i::GetSubMeshOnSolidTag()
103 return SMESH::Tag_SubMeshOnSolid;
106 long SMESH_Gen_i::GetSubMeshOnCompoundTag()
108 return SMESH::Tag_SubMeshOnCompound;
111 long SMESH_Gen_i::GetSubMeshOnWireTag()
113 return SMESH::Tag_SubMeshOnWire;
116 long SMESH_Gen_i::GetSubMeshOnShellTag()
118 return SMESH::Tag_SubMeshOnShell;
121 long SMESH_Gen_i::GetNodeGroupsTag()
123 return SMESH::Tag_NodeGroups;
126 long SMESH_Gen_i::GetEdgeGroupsTag()
128 return SMESH::Tag_EdgeGroups;
131 long SMESH_Gen_i::GetFaceGroupsTag()
133 return SMESH::Tag_FaceGroups;
136 long SMESH_Gen_i::GetVolumeGroupsTag()
138 return SMESH::Tag_VolumeGroups;
141 long SMESH_Gen_i::Get0DElementsGroupsTag()
143 return SMESH::Tag_0DElementsGroups;
146 //=============================================================================
148 * SMESH_Gen_i::CanPublishInStudy
150 * Returns true if object can be published in the study
152 //=============================================================================
154 bool SMESH_Gen_i::CanPublishInStudy(CORBA::Object_ptr theIOR)
156 if(MYDEBUG) MESSAGE("CanPublishInStudy - "<<!CORBA::is_nil(myCurrentStudy));
157 if(CORBA::is_nil(myCurrentStudy))
160 SMESH::SMESH_Mesh_var aMesh = SMESH::SMESH_Mesh::_narrow(theIOR);
161 if( !aMesh->_is_nil() )
164 SMESH::SMESH_subMesh_var aSubMesh = SMESH::SMESH_subMesh::_narrow(theIOR);
165 if( !aSubMesh->_is_nil() )
168 SMESH::SMESH_Hypothesis_var aHyp = SMESH::SMESH_Hypothesis::_narrow(theIOR);
169 if( !aHyp->_is_nil() )
172 SMESH::SMESH_GroupBase_var aGroup = SMESH::SMESH_GroupBase::_narrow(theIOR);
173 if( !aGroup->_is_nil() )
176 if(MYDEBUG) MESSAGE("CanPublishInStudy--CANT");
180 //=======================================================================
181 //function : ObjectToSObject
183 //=======================================================================
185 SALOMEDS::SObject_ptr SMESH_Gen_i::ObjectToSObject(SALOMEDS::Study_ptr theStudy,
186 CORBA::Object_ptr theObject)
188 SALOMEDS::SObject_var aSO;
189 if ( !CORBA::is_nil( theStudy ) && !CORBA::is_nil( theObject ))
191 CORBA::String_var objStr = SMESH_Gen_i::GetORB()->object_to_string( theObject );
192 aSO = theStudy->FindObjectIOR( objStr.in() );
197 //=======================================================================
198 //function : objectToServant
200 //=======================================================================
202 template<typename T> static inline T* objectToServant( CORBA::Object_ptr theIOR )
204 return dynamic_cast<T*>( SMESH_Gen_i::GetServant( theIOR ).in() );
207 //=======================================================================
208 //function : ShapeToGeomObject
210 //=======================================================================
212 GEOM::GEOM_Object_ptr SMESH_Gen_i::ShapeToGeomObject (const TopoDS_Shape& theShape )
214 GEOM::GEOM_Object_var aShapeObj;
215 if ( !theShape.IsNull() ) {
216 GEOM_Client* aClient = GetShapeReader();
217 TCollection_AsciiString IOR;
218 if ( aClient && aClient->Find( theShape, IOR ))
220 CORBA::Object_var obj = GetORB()->string_to_object( IOR.ToCString() );
221 aShapeObj = GEOM::GEOM_Object::_narrow ( obj );
224 return aShapeObj._retn();
227 //=======================================================================
228 //function : GeomObjectToShape
230 //=======================================================================
232 TopoDS_Shape SMESH_Gen_i::GeomObjectToShape(GEOM::GEOM_Object_ptr theGeomObject)
235 if ( !theGeomObject->_is_nil() ) {
236 GEOM_Client* aClient = GetShapeReader();
237 GEOM::GEOM_Gen_ptr aGeomEngine = GetGeomEngine();
238 if ( aClient && !aGeomEngine->_is_nil () )
239 S = aClient->GetShape( aGeomEngine, theGeomObject );
244 //=======================================================================
247 //=======================================================================
249 static SALOMEDS::SObject_ptr publish(SALOMEDS::Study_ptr theStudy,
250 CORBA::Object_ptr theIOR,
251 SALOMEDS::SObject_ptr theFatherObject,
252 const int theTag = 0,
253 const char* thePixMap = 0,
254 const bool theSelectable = true)
256 SALOMEDS::SObject_var SO = SMESH_Gen_i::ObjectToSObject( theStudy, theIOR );
257 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
258 if ( SO->_is_nil() ) {
260 SO = aStudyBuilder->NewObject( theFatherObject );
261 else if ( !theFatherObject->FindSubObject( theTag, SO ))
262 SO = aStudyBuilder->NewObjectToTag( theFatherObject, theTag );
265 SALOMEDS::GenericAttribute_var anAttr;
266 if ( !CORBA::is_nil( theIOR )) {
267 anAttr = aStudyBuilder->FindOrCreateAttribute( SO, "AttributeIOR" );
268 CORBA::String_var objStr = SMESH_Gen_i::GetORB()->object_to_string( theIOR );
269 SALOMEDS::AttributeIOR::_narrow(anAttr)->SetValue( objStr.in() );
272 anAttr = aStudyBuilder->FindOrCreateAttribute( SO, "AttributePixMap" );
273 SALOMEDS::AttributePixMap_var pm = SALOMEDS::AttributePixMap::_narrow( anAttr );
274 pm->SetPixMap( thePixMap );
276 if ( !theSelectable ) {
277 anAttr = aStudyBuilder->FindOrCreateAttribute( SO, "AttributeSelectable" );
278 SALOMEDS::AttributeSelectable::_narrow( anAttr )->SetSelectable( false );
283 //=======================================================================
286 //=======================================================================
288 void SMESH_Gen_i::SetName(SALOMEDS::SObject_ptr theSObject,
290 const char* theDefaultName)
292 if ( !theSObject->_is_nil() ) {
293 SALOMEDS::StudyBuilder_var aStudyBuilder = theSObject->GetStudy()->NewBuilder();
294 SALOMEDS::GenericAttribute_var anAttr =
295 aStudyBuilder->FindOrCreateAttribute( theSObject, "AttributeName" );
296 SALOMEDS::AttributeName_var aNameAttr = SALOMEDS::AttributeName::_narrow( anAttr );
297 if ( theName && strlen( theName ) != 0 )
298 aNameAttr->SetValue( theName );
300 CORBA::String_var curName = CORBA::string_dup( aNameAttr->Value() );
301 if ( strlen( curName ) == 0 ) {
302 TCollection_AsciiString aName( (char*) theDefaultName );
303 aName += TCollection_AsciiString("_") + TCollection_AsciiString( theSObject->Tag() );
304 aNameAttr->SetValue( aName.ToCString() );
310 //=======================================================================
311 //function : SetPixMap
313 //=======================================================================
315 void SMESH_Gen_i::SetPixMap(SALOMEDS::SObject_ptr theSObject,
316 const char* thePixMap)
318 if ( !theSObject->_is_nil() && thePixMap && strlen( thePixMap ))
320 SALOMEDS::Study_var aStudy = theSObject->GetStudy();
321 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
322 SALOMEDS::GenericAttribute_var anAttr =
323 aStudyBuilder->FindOrCreateAttribute( theSObject, "AttributePixMap" );
324 SALOMEDS::AttributePixMap_var aPMAttr = SALOMEDS::AttributePixMap::_narrow( anAttr );
325 aPMAttr->SetPixMap( thePixMap );
329 //=======================================================================
330 //function : addReference
332 //=======================================================================
334 static void addReference (SALOMEDS::Study_ptr theStudy,
335 SALOMEDS::SObject_ptr theSObject,
336 CORBA::Object_ptr theToObject,
339 SALOMEDS::SObject_var aToObjSO = SMESH_Gen_i::ObjectToSObject( theStudy, theToObject );
340 if ( !aToObjSO->_is_nil() && !theSObject->_is_nil() ) {
341 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
342 SALOMEDS::SObject_var aReferenceSO;
344 // check if the reference to theToObject already exists
345 // and find a free label for the reference object
346 bool isReferred = false;
348 SALOMEDS::ChildIterator_var anIter = theStudy->NewChildIterator( theSObject );
349 for ( ; !isReferred && anIter->More(); anIter->Next(), ++tag ) {
350 if ( anIter->Value()->ReferencedObject( aReferenceSO )) {
351 if ( strcmp( aReferenceSO->GetID(), aToObjSO->GetID() ) == 0 )
354 else if ( !theTag ) {
355 SALOMEDS::GenericAttribute_var anAttr;
356 if ( !anIter->Value()->FindAttribute( anAttr, "AttributeIOR" ))
365 if ( !theSObject->FindSubObject( theTag, aReferenceSO ))
366 aReferenceSO = aStudyBuilder->NewObjectToTag( theSObject, theTag );
367 aStudyBuilder->Addreference( aReferenceSO, aToObjSO );
371 //=============================================================================
373 * SMESH_Gen_i::PublishInStudy
375 * Publish object in the study
377 //=============================================================================
379 SALOMEDS::SObject_ptr SMESH_Gen_i::PublishInStudy(SALOMEDS::Study_ptr theStudy,
380 SALOMEDS::SObject_ptr theSObject,
381 CORBA::Object_ptr theIOR,
383 throw (SALOME::SALOME_Exception)
385 Unexpect aCatch(SALOME_SalomeException);
386 SALOMEDS::SObject_var aSO;
387 if ( CORBA::is_nil( theStudy ) || CORBA::is_nil( theIOR ))
389 if(MYDEBUG) MESSAGE("PublishInStudy");
392 SMESH::SMESH_Mesh_var aMesh = SMESH::SMESH_Mesh::_narrow( theIOR );
393 if( !aMesh->_is_nil() )
394 aSO = PublishMesh( theStudy, aMesh, theName );
396 // Publishing a sub-mesh
397 SMESH::SMESH_subMesh_var aSubMesh = SMESH::SMESH_subMesh::_narrow( theIOR );
398 if( aSO->_is_nil() && !aSubMesh->_is_nil() ) {
399 GEOM::GEOM_Object_var aShapeObject = aSubMesh->GetSubShape();
400 aMesh = aSubMesh->GetFather();
401 aSO = PublishSubMesh( theStudy, aMesh, aSubMesh, aShapeObject, theName );
404 // Publishing a hypothesis or algorithm
405 SMESH::SMESH_Hypothesis_var aHyp = SMESH::SMESH_Hypothesis::_narrow( theIOR );
406 if ( aSO->_is_nil() && !aHyp->_is_nil() )
407 aSO = PublishHypothesis( theStudy, aHyp );
409 // Publishing a group
410 SMESH::SMESH_GroupBase_var aGroup = SMESH::SMESH_GroupBase::_narrow(theIOR);
411 if ( aSO->_is_nil() && !aGroup->_is_nil() ) {
412 GEOM::GEOM_Object_var aShapeObject;
413 aMesh = aGroup->GetMesh();
414 aSO = PublishGroup( theStudy, aMesh, aGroup, aShapeObject, theName );
416 if(MYDEBUG) MESSAGE("PublishInStudy_END");
421 //=======================================================================
422 //function : PublishComponent
424 //=======================================================================
426 SALOMEDS::SComponent_ptr SMESH_Gen_i::PublishComponent(SALOMEDS::Study_ptr theStudy)
428 if ( CORBA::is_nil( theStudy ))
429 return SALOMEDS::SComponent::_nil();
430 if(MYDEBUG) MESSAGE("PublishComponent");
432 SALOMEDS::SComponent_var father =
433 SALOMEDS::SComponent::_narrow( theStudy->FindComponent( ComponentDataType() ) );
434 if ( !CORBA::is_nil( father ) )
435 return father._retn();
437 SALOME_ModuleCatalog::ModuleCatalog_var aCat =
438 SALOME_ModuleCatalog::ModuleCatalog::_narrow( GetNS()->Resolve("/Kernel/ModulCatalog") );
439 if ( CORBA::is_nil( aCat ) )
440 return father._retn();
442 SALOME_ModuleCatalog::Acomponent_var aComp = aCat->GetComponent( ComponentDataType() );
443 if ( CORBA::is_nil( aComp ) )
444 return father._retn();
446 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
447 SALOMEDS::GenericAttribute_var anAttr;
448 SALOMEDS::AttributePixMap_var aPixmap;
450 father = aStudyBuilder->NewComponent( ComponentDataType() );
451 aStudyBuilder->DefineComponentInstance( father, SMESH_Gen::_this() );
452 anAttr = aStudyBuilder->FindOrCreateAttribute( father, "AttributePixMap" );
453 aPixmap = SALOMEDS::AttributePixMap::_narrow( anAttr );
454 aPixmap ->SetPixMap( "ICON_OBJBROWSER_SMESH" );
455 SetName( father, aComp->componentusername(), "MESH" );
456 if(MYDEBUG) MESSAGE("PublishComponent--END");
458 return father._retn();
461 //=============================================================================
463 * findMaxChildTag [ static internal ]
465 * Finds maximum child tag for the given object
467 //=============================================================================
469 static long findMaxChildTag( SALOMEDS::SObject_ptr theSObject )
472 if ( !theSObject->_is_nil() ) {
473 SALOMEDS::Study_var aStudy = theSObject->GetStudy();
474 if ( !aStudy->_is_nil() ) {
475 SALOMEDS::ChildIterator_var anIter = aStudy->NewChildIterator( theSObject );
476 for ( ; anIter->More(); anIter->Next() ) {
477 long nTag = anIter->Value()->Tag();
486 //=======================================================================
487 //function : PublishMesh
489 //=======================================================================
491 SALOMEDS::SObject_ptr SMESH_Gen_i::PublishMesh (SALOMEDS::Study_ptr theStudy,
492 SMESH::SMESH_Mesh_ptr theMesh,
495 if ( CORBA::is_nil( theStudy ) ||
496 CORBA::is_nil( theMesh ))
497 return SALOMEDS::SComponent::_nil();
498 if(MYDEBUG) MESSAGE("PublishMesh--IN");
500 // find or publish a mesh
502 SALOMEDS::SObject_var aMeshSO = ObjectToSObject( theStudy, theMesh );
503 if ( aMeshSO->_is_nil() )
505 SALOMEDS::SComponent_var father = PublishComponent( theStudy );
506 if ( father->_is_nil() )
507 return aMeshSO._retn();
509 // Find correct free tag
510 long aTag = findMaxChildTag( father.in() );
511 if ( aTag <= GetAlgorithmsRootTag() )
512 aTag = GetAlgorithmsRootTag() + 1;
516 aMeshSO = publish (theStudy, theMesh, father, aTag, "ICON_SMESH_TREE_MESH_WARN" );
517 if ( aMeshSO->_is_nil() )
518 return aMeshSO._retn();
520 SetName( aMeshSO, theName, "Mesh" );
522 // Add shape reference
524 GEOM::GEOM_Object_var aShapeObject = theMesh->GetShapeToMesh();
525 if ( !CORBA::is_nil( aShapeObject )) {
526 addReference( theStudy, aMeshSO, aShapeObject, GetRefOnShapeTag() );
528 // Publish global hypotheses
530 SMESH::ListOfHypothesis_var hypList = theMesh->GetHypothesisList( aShapeObject );
531 for ( int i = 0; i < hypList->length(); i++ ) {
532 SMESH::SMESH_Hypothesis_var aHyp = SMESH::SMESH_Hypothesis::_narrow( hypList[ i ]);
533 PublishHypothesis( theStudy, aHyp );
534 AddHypothesisToShape( theStudy, theMesh, aShapeObject, aHyp );
540 SMESH_Mesh_i* mesh_i = objectToServant<SMESH_Mesh_i>( theMesh );
542 return aMeshSO._retn();
543 map<int, SMESH_subMesh_i*>& subMap = mesh_i->_mapSubMesh_i;
544 map<int, SMESH_subMesh_i*>::iterator subIt = subMap.begin();
545 for ( ; subIt != subMap.end(); subIt++ ) {
546 SMESH::SMESH_subMesh_ptr aSubMesh = (*subIt).second->_this();
547 if ( !CORBA::is_nil( aSubMesh )) {
548 aShapeObject = aSubMesh->GetSubShape();
549 PublishSubMesh( theStudy, theMesh, aSubMesh, aShapeObject );
554 const map<int, SMESH::SMESH_GroupBase_ptr>& grMap = mesh_i->getGroups();
555 map<int, SMESH::SMESH_GroupBase_ptr>::const_iterator it = grMap.begin();
556 for ( ; it != grMap.end(); it++ )
558 SMESH::SMESH_GroupBase_ptr aGroup = (*it).second;
559 if ( !aGroup->_is_nil() ) {
560 GEOM::GEOM_Object_var aShapeObj;
561 SMESH::SMESH_GroupOnGeom_var aGeomGroup =
562 SMESH::SMESH_GroupOnGeom::_narrow( aGroup );
563 if ( !aGeomGroup->_is_nil() )
564 aShapeObj = aGeomGroup->GetShape();
565 PublishGroup( theStudy, theMesh, aGroup, aShapeObj );
569 if(MYDEBUG) MESSAGE("PublishMesh_END");
570 return aMeshSO._retn();
573 //=======================================================================
574 //function : PublishSubMesh
576 //=======================================================================
578 SALOMEDS::SObject_ptr SMESH_Gen_i::PublishSubMesh (SALOMEDS::Study_ptr theStudy,
579 SMESH::SMESH_Mesh_ptr theMesh,
580 SMESH::SMESH_subMesh_ptr theSubMesh,
581 GEOM::GEOM_Object_ptr theShapeObject,
584 if (theStudy->_is_nil() || theMesh->_is_nil() ||
585 theSubMesh->_is_nil() || theShapeObject->_is_nil() )
586 return SALOMEDS::SObject::_nil();
588 SALOMEDS::SObject_var aSubMeshSO = ObjectToSObject( theStudy, theSubMesh );
589 if ( aSubMeshSO->_is_nil() )
591 SALOMEDS::SObject_var aMeshSO = ObjectToSObject( theStudy, theMesh );
592 if ( aMeshSO->_is_nil() ) {
593 aMeshSO = PublishMesh( theStudy, theMesh );
594 if ( aMeshSO->_is_nil())
595 return SALOMEDS::SObject::_nil();
597 // Find submesh sub-tree tag
599 const char* aRootName = "";
600 switch ( theShapeObject->GetShapeType() ) {
602 aRootTag = GetSubMeshOnVertexTag();
603 aRootName = "SubMeshes on Vertex";
606 aRootTag = GetSubMeshOnEdgeTag();
607 aRootName = "SubMeshes on Edge";
610 aRootTag = GetSubMeshOnWireTag();
611 aRootName = "SubMeshes on Wire";
614 aRootTag = GetSubMeshOnFaceTag();
615 aRootName = "SubMeshes on Face";
618 aRootTag = GetSubMeshOnShellTag();
619 aRootName = "SubMeshes on Shell";
622 aRootTag = GetSubMeshOnSolidTag();
623 aRootName = "SubMeshes on Solid";
626 aRootTag = GetSubMeshOnCompoundTag();
627 aRootName = "SubMeshes on Compound";
631 // Find or create submesh root
632 SALOMEDS::SObject_var aRootSO = publish (theStudy, CORBA::Object::_nil(),
633 aMeshSO, aRootTag, 0, false );
634 SetName( aRootSO, aRootName );
636 // Add new submesh to corresponding sub-tree
637 aSubMeshSO = publish (theStudy, theSubMesh, aRootSO, 0, "ICON_SMESH_TREE_MESH_WARN");
638 if ( aSubMeshSO->_is_nil() )
639 return aSubMeshSO._retn();
641 SetName( aSubMeshSO, theName, "SubMesh" );
643 // Add reference to theShapeObject
645 addReference( theStudy, aSubMeshSO, theShapeObject, 1 );
647 // Publish hypothesis
649 SMESH::ListOfHypothesis * hypList = theMesh->GetHypothesisList( theShapeObject );
651 for ( int i = 0; i < hypList->length(); i++ ) {
652 SMESH::SMESH_Hypothesis_var aHyp = SMESH::SMESH_Hypothesis::_narrow( (*hypList)[ i ]);
653 PublishHypothesis( theStudy, aHyp );
654 AddHypothesisToShape( theStudy, theMesh, theShapeObject, aHyp );
657 return aSubMeshSO._retn();
660 //=======================================================================
661 //function : PublishGroup
663 //=======================================================================
665 SALOMEDS::SObject_ptr SMESH_Gen_i::PublishGroup (SALOMEDS::Study_ptr theStudy,
666 SMESH::SMESH_Mesh_ptr theMesh,
667 SMESH::SMESH_GroupBase_ptr theGroup,
668 GEOM::GEOM_Object_ptr theShapeObject,
671 if (theStudy->_is_nil() || theMesh->_is_nil() || theGroup->_is_nil() )
672 return SALOMEDS::SObject::_nil();
674 SALOMEDS::SObject_var aGroupSO = ObjectToSObject( theStudy, theGroup );
675 if ( aGroupSO->_is_nil() )
677 SALOMEDS::SObject_var aMeshSO = ObjectToSObject( theStudy, theMesh );
678 if ( aMeshSO->_is_nil() ) {
679 aMeshSO = PublishInStudy( theStudy, SALOMEDS::SObject::_nil(), theMesh, "");
680 if ( aMeshSO->_is_nil())
681 return SALOMEDS::SObject::_nil();
683 int aType = (int)theGroup->GetType();
684 const char* aRootNames[] = {
685 "Compound Groups", "Groups of Nodes", "Groups of Edges",
686 "Groups of Faces", "Groups of Volumes", "Groups of 0D Elements" };
688 // Currently, groups with heterogenous content are not supported
689 if ( aType != SMESH::ALL ) {
690 long aRootTag = GetNodeGroupsTag() + aType - 1;
692 // Find or create groups root
693 SALOMEDS::SObject_var aRootSO = publish (theStudy, CORBA::Object::_nil(),
694 aMeshSO, aRootTag, 0, false );
696 SetName( aRootSO, aRootNames[aType] );
698 // Add new group to corresponding sub-tree
699 aGroupSO = publish (theStudy, theGroup, aRootSO, 0, "ICON_SMESH_TREE_GROUP" );
701 if ( aGroupSO->_is_nil() )
702 return aGroupSO._retn();
705 SetName( aGroupSO, theName, "Group" );
707 //Add reference to geometry
708 if ( !theShapeObject->_is_nil() )
709 addReference( theStudy, aGroupSO, theShapeObject, 1 );
711 return aGroupSO._retn();
714 //=======================================================================
715 //function : PublishHypothesis
717 //=======================================================================
719 SALOMEDS::SObject_ptr
720 SMESH_Gen_i::PublishHypothesis (SALOMEDS::Study_ptr theStudy,
721 SMESH::SMESH_Hypothesis_ptr theHyp,
724 if(MYDEBUG) MESSAGE("PublishHypothesis")
725 if (theStudy->_is_nil() || theHyp->_is_nil())
726 return SALOMEDS::SObject::_nil();
728 SALOMEDS::SObject_var aHypSO = ObjectToSObject( theStudy, theHyp );
729 if ( aHypSO->_is_nil() )
731 SALOMEDS::SComponent_var father = PublishComponent( theStudy );
732 if ( father->_is_nil() )
733 return aHypSO._retn();
735 //Find or Create Hypothesis root
736 bool isAlgo = ( !SMESH::SMESH_Algo::_narrow( theHyp )->_is_nil() );
737 int aRootTag = isAlgo ? GetAlgorithmsRootTag() : GetHypothesisRootTag();
738 SALOMEDS::SObject_var aRootSO =
739 publish (theStudy, CORBA::Object::_nil(),father, aRootTag,
740 isAlgo ? "ICON_SMESH_TREE_ALGO" : "ICON_SMESH_TREE_HYPO", false);
741 SetName( aRootSO, isAlgo ? "Algorithms" : "Hypotheses" );
743 // Add New Hypothesis
744 string aPmName = isAlgo ? "ICON_SMESH_TREE_ALGO_" : "ICON_SMESH_TREE_HYPO_";
745 aPmName += theHyp->GetName();
746 // prepend plugin name to pixmap name
747 string pluginName = myHypCreatorMap[string(theHyp->GetName())]->GetModuleName();
748 if ( pluginName != "StdMeshers" )
749 aPmName = pluginName + "::" + aPmName;
750 aHypSO = publish( theStudy, theHyp, aRootSO, 0, aPmName.c_str() );
753 if ( !aHypSO->_is_nil() ) {
754 CORBA::String_var aHypName = CORBA::string_dup( theHyp->GetName() );
755 SetName( aHypSO, theName, aHypName );
758 if(MYDEBUG) MESSAGE("PublishHypothesis--END")
759 return aHypSO._retn();
762 //=======================================================================
763 //function : GetMeshOrSubmeshByShape
765 //=======================================================================
767 SALOMEDS::SObject_ptr
768 SMESH_Gen_i::GetMeshOrSubmeshByShape (SALOMEDS::Study_ptr theStudy,
769 SMESH::SMESH_Mesh_ptr theMesh,
770 GEOM::GEOM_Object_ptr theShape)
772 if(MYDEBUG) MESSAGE("GetMeshOrSubmeshByShape")
773 SALOMEDS::SObject_var aMeshOrSubMesh;
774 if (theMesh->_is_nil() || ( theShape->_is_nil() && theMesh->HasShapeToMesh()))
775 return aMeshOrSubMesh._retn();
778 if(theMesh->HasShapeToMesh())
779 aShape = GeomObjectToShape( theShape );
781 aShape = SMESH_Mesh::PseudoShape();
783 SMESH_Mesh_i* mesh_i = objectToServant<SMESH_Mesh_i>( theMesh );
785 if ( !aShape.IsNull() && mesh_i && mesh_i->GetImpl().GetMeshDS() ) {
786 SMESHDS_Mesh* meshDS = mesh_i->GetImpl().GetMeshDS();
787 if ( aShape.IsSame( meshDS->ShapeToMesh() ))
788 aMeshOrSubMesh = ObjectToSObject( theStudy, theMesh );
790 int shapeID = meshDS->ShapeToIndex( aShape );
791 SMESH::SMESH_subMesh_var aSubMesh = mesh_i->getSubMesh(shapeID);
792 if ( !aSubMesh->_is_nil() )
793 aMeshOrSubMesh = ObjectToSObject( theStudy, aSubMesh );
796 if(MYDEBUG) MESSAGE("GetMeshOrSubmeshByShape--END")
797 return aMeshOrSubMesh._retn();
800 //=======================================================================
801 //function : AddHypothesisToShape
803 //=======================================================================
805 bool SMESH_Gen_i::AddHypothesisToShape(SALOMEDS::Study_ptr theStudy,
806 SMESH::SMESH_Mesh_ptr theMesh,
807 GEOM::GEOM_Object_ptr theShape,
808 SMESH::SMESH_Hypothesis_ptr theHyp)
810 if(MYDEBUG) MESSAGE("AddHypothesisToShape")
811 if (theStudy->_is_nil() || theMesh->_is_nil() ||
812 theHyp->_is_nil() || (theShape->_is_nil()
813 && theMesh->HasShapeToMesh()) )
816 SALOMEDS::SObject_var aMeshSO = ObjectToSObject( theStudy, theMesh );
817 if ( aMeshSO->_is_nil() )
818 aMeshSO = PublishMesh( theStudy, theMesh );
819 SALOMEDS::SObject_var aHypSO = PublishHypothesis( theStudy, theHyp );
820 if ( aMeshSO->_is_nil() || aHypSO->_is_nil())
823 // Find a mesh or submesh refering to theShape
824 SALOMEDS::SObject_var aMeshOrSubMesh =
825 GetMeshOrSubmeshByShape( theStudy, theMesh, theShape );
826 if ( aMeshOrSubMesh->_is_nil() )
829 TopoDS_Shape aShape = GeomObjectToShape( theShape );
830 SMESH_Mesh_i* mesh_i = objectToServant<SMESH_Mesh_i>( theMesh );
831 if ( !aShape.IsNull() && mesh_i && mesh_i->GetImpl().GetMeshDS() ) {
832 SMESHDS_Mesh* meshDS = mesh_i->GetImpl().GetMeshDS();
833 int shapeID = meshDS->ShapeToIndex( aShape );
834 SMESH::SMESH_subMesh_var aSubMesh = mesh_i->getSubMesh(shapeID);
835 aMeshOrSubMesh = PublishSubMesh( theStudy, theMesh, aSubMesh, theShape );
837 if ( aMeshOrSubMesh->_is_nil() )
841 //Find or Create Applied Hypothesis root
842 bool aIsAlgo = !SMESH::SMESH_Algo::_narrow( theHyp )->_is_nil();
843 SALOMEDS::SObject_var AHR =
844 publish (theStudy, CORBA::Object::_nil(), aMeshOrSubMesh,
845 aIsAlgo ? GetRefOnAppliedAlgorithmsTag() : GetRefOnAppliedHypothesisTag(),
846 aIsAlgo ? "ICON_SMESH_TREE_ALGO" : "ICON_SMESH_TREE_HYPO", false);
847 SetName( AHR, aIsAlgo ? "Applied algorithms" : "Applied hypotheses" );
848 if ( AHR->_is_nil() )
851 addReference( theStudy, AHR, theHyp );
852 if(MYDEBUG) MESSAGE("AddHypothesisToShape--END")
856 //=======================================================================
857 //function : RemoveHypothesisFromShape
859 //=======================================================================
861 bool SMESH_Gen_i::RemoveHypothesisFromShape(SALOMEDS::Study_ptr theStudy,
862 SMESH::SMESH_Mesh_ptr theMesh,
863 GEOM::GEOM_Object_ptr theShape,
864 SMESH::SMESH_Hypothesis_ptr theHyp)
866 if (theStudy->_is_nil() || theMesh->_is_nil() ||
867 theHyp->_is_nil() || (theShape->_is_nil()
868 && theMesh->HasShapeToMesh()))
871 SALOMEDS::SObject_var aHypSO = ObjectToSObject( theStudy, theHyp );
872 if ( aHypSO->_is_nil() )
875 // Find a mesh or submesh refering to theShape
876 SALOMEDS::SObject_var aMeshOrSubMesh =
877 GetMeshOrSubmeshByShape( theStudy, theMesh, theShape );
878 if ( aMeshOrSubMesh->_is_nil() )
881 // Find and remove a reference to aHypSO
882 SALOMEDS::SObject_var aRef, anObj;
883 CORBA::String_var anID = CORBA::string_dup( aHypSO->GetID() );
884 SALOMEDS::ChildIterator_var it = theStudy->NewChildIterator( aMeshOrSubMesh );
885 for ( it->InitEx( true ); it->More(); it->Next() ) {
887 if (anObj->ReferencedObject( aRef ) && strcmp( aRef->GetID(), anID ) == 0 ) {
888 theStudy->NewBuilder()->RemoveObject( anObj );
895 //=======================================================================
896 //function : UpdateParameters
898 //=======================================================================
899 void SMESH_Gen_i::UpdateParameters(CORBA::Object_ptr theObject, const char* theParameters)
903 cout<<"UpdateParameters : "<<theParameters<<endl;
904 SALOMEDS::Study_ptr aStudy = GetCurrentStudy();
905 if(aStudy->_is_nil() || CORBA::is_nil(theObject))
908 SALOMEDS::SObject_var aSObj = ObjectToSObject(aStudy,theObject);
912 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
914 SALOMEDS::GenericAttribute_var aFindAttr;
915 bool hasAttr = aSObj->FindAttribute(aFindAttr, "AttributeString");
917 cout<<"Find Attribute "<<hasAttr<<endl;
919 SALOMEDS::GenericAttribute_var anAttr;
920 anAttr = aStudyBuilder->FindOrCreateAttribute( aSObj, "AttributeString");
921 SALOMEDS::AttributeString_var aStringAttr = SALOMEDS::AttributeString::_narrow(anAttr);
923 CORBA::String_var oldparVar = aStringAttr->Value();
924 CORBA::String_var inpparVar = ParseParameters(theParameters);
925 TCollection_AsciiString aNewParams;
926 TCollection_AsciiString aOldParameters(oldparVar.inout());
927 TCollection_AsciiString anInputParams(inpparVar.inout());
929 aNewParams = anInputParams;
932 int pos = aOldParameters.SearchFromEnd("|");
934 TCollection_AsciiString previousParamFull(aOldParameters.Split(pos));
935 TCollection_AsciiString previousParam(previousParamFull);
936 TCollection_AsciiString theRepet("1");
937 pos = previousParam.SearchFromEnd(";*=");
940 theRepet = previousParam.Split(pos+2);
943 previousParam.Split(pos);
945 if(previousParam == anInputParams)
947 theRepet = theRepet.IntegerValue()+1;
948 aNewParams = aOldParameters + previousParam + ";*=" + theRepet;
952 aNewParams = aOldParameters + previousParamFull + "|" + anInputParams;
958 cout<<"Input Parameters : "<<anInputParams<<endl;
959 cout<<"Old Parameters : "<<aOldParameters<<endl;
960 cout<<"New Parameters : "<<aNewParams<<endl;
963 aStringAttr->SetValue( aNewParams.ToCString() );
966 //=======================================================================
967 //function : ParseParameters
969 //=======================================================================
970 char* SMESH_Gen_i::ParseParameters(const char* theParameters)
972 //const char* aParameters = theParameters;
973 // const char* aParameters = CORBA::string_dup(theParameters);
974 TCollection_AsciiString anInputParams;
975 SALOMEDS::Study_var aStudy = GetCurrentStudy();
976 if( !aStudy->_is_nil() ) {
977 // SALOMEDS::ListOfListOfStrings_var aSections = aStudy->ParseVariables(theParameters);
978 // for(int j=0;j<aSections->length();j++) {
979 // SALOMEDS::ListOfStrings aVars= aSections[j];
980 // for(int i=0;i<aVars.length();i++ ) {
981 // anInputParams += aStudy->IsVariable(aVars[i].in()) ?
982 // TCollection_AsciiString(aVars[i].in()) : TCollection_AsciiString("");
983 // if(i != aVars.length()-1)
984 // anInputParams+=":";
986 // if(j!=aSections->length()-1)
987 // anInputParams+="|";
989 TCollection_AsciiString paramStr( theParameters );
990 static TCollection_AsciiString separators(":|");
992 char sep, *pParams = (char*)paramStr.ToCString();
993 while ( beg < paramStr.Length() )
996 while ( ++end < paramStr.Length() )
997 if ( pParams[end] == ':' || pParams[end] == '|')
999 if ( end < paramStr.Length())
1002 pParams[end] = '\0';
1004 if ( aStudy->IsVariable( pParams+beg ))
1005 anInputParams += pParams+beg;
1006 if ( end < paramStr.Length() )
1007 anInputParams += sep;
1013 return CORBA::string_dup(anInputParams.ToCString());
1016 //=======================================================================
1017 //function : GetParameters
1019 //=======================================================================
1020 char* SMESH_Gen_i::GetParameters(CORBA::Object_ptr theObject)
1022 TCollection_AsciiString aResult;
1024 SALOMEDS::Study_ptr aStudy = GetCurrentStudy();
1025 SALOMEDS::SObject_var aSObj = ObjectToSObject(aStudy,theObject);
1027 if(!aStudy->_is_nil() &&
1028 !CORBA::is_nil(theObject) &&
1031 SALOMEDS::GenericAttribute_var anAttr;
1032 if ( aSObj->FindAttribute(anAttr, "AttributeString")) {
1033 aResult = TCollection_AsciiString(SALOMEDS::AttributeString::_narrow(anAttr)->Value());
1037 return CORBA::string_dup( aResult.ToCString() );