1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // SMESH SMESH_I : idl implementation based on 'SMESH' unit's calsses
23 // File : SMESH_Gen_i_1.cxx
24 // Created : Thu Oct 21 17:24:06 2004
25 // Author : Edward AGAPOV (eap)
29 #include "SMESH_Gen_i.hxx"
31 #include "SMESH_Mesh_i.hxx"
32 #include "SMESH_Hypothesis_i.hxx"
33 #include "SMESH_Algo_i.hxx"
34 #include "SMESH_Group_i.hxx"
35 #include "SMESH_subMesh_i.hxx"
37 #include CORBA_CLIENT_HEADER(SALOME_ModuleCatalog)
39 #include "utilities.h"
40 #include "Utils_ExceptHandlers.hxx"
42 #include <TCollection_AsciiString.hxx>
45 static int MYDEBUG = 0;
46 static int VARIABLE_DEBUG = 0;
48 static int MYDEBUG = 0;
49 static int VARIABLE_DEBUG = 0;
52 //=============================================================================
54 * Get...Tag [ static ]
56 * Methods which determine SMESH data model structure
58 //=============================================================================
60 long SMESH_Gen_i::GetHypothesisRootTag()
62 return SMESH::Tag_HypothesisRoot;
65 long SMESH_Gen_i::GetAlgorithmsRootTag()
67 return SMESH::Tag_AlgorithmsRoot;
70 long SMESH_Gen_i::GetRefOnShapeTag()
72 return SMESH::Tag_RefOnShape;
75 long SMESH_Gen_i::GetRefOnAppliedHypothesisTag()
77 return SMESH::Tag_RefOnAppliedHypothesis;
80 long SMESH_Gen_i::GetRefOnAppliedAlgorithmsTag()
82 return SMESH::Tag_RefOnAppliedAlgorithms;
85 long SMESH_Gen_i::GetSubMeshOnVertexTag()
87 return SMESH::Tag_SubMeshOnVertex;
90 long SMESH_Gen_i::GetSubMeshOnEdgeTag()
92 return SMESH::Tag_SubMeshOnEdge;
95 long SMESH_Gen_i::GetSubMeshOnFaceTag()
97 return SMESH::Tag_SubMeshOnFace;
100 long SMESH_Gen_i::GetSubMeshOnSolidTag()
102 return SMESH::Tag_SubMeshOnSolid;
105 long SMESH_Gen_i::GetSubMeshOnCompoundTag()
107 return SMESH::Tag_SubMeshOnCompound;
110 long SMESH_Gen_i::GetSubMeshOnWireTag()
112 return SMESH::Tag_SubMeshOnWire;
115 long SMESH_Gen_i::GetSubMeshOnShellTag()
117 return SMESH::Tag_SubMeshOnShell;
120 long SMESH_Gen_i::GetNodeGroupsTag()
122 return SMESH::Tag_NodeGroups;
125 long SMESH_Gen_i::GetEdgeGroupsTag()
127 return SMESH::Tag_EdgeGroups;
130 long SMESH_Gen_i::GetFaceGroupsTag()
132 return SMESH::Tag_FaceGroups;
135 long SMESH_Gen_i::GetVolumeGroupsTag()
137 return SMESH::Tag_VolumeGroups;
140 //=============================================================================
142 * SMESH_Gen_i::CanPublishInStudy
144 * Returns true if object can be published in the study
146 //=============================================================================
148 bool SMESH_Gen_i::CanPublishInStudy(CORBA::Object_ptr theIOR)
150 if(MYDEBUG) MESSAGE("CanPublishInStudy - "<<!CORBA::is_nil(myCurrentStudy));
151 if(CORBA::is_nil(myCurrentStudy))
154 SMESH::SMESH_Mesh_var aMesh = SMESH::SMESH_Mesh::_narrow(theIOR);
155 if( !aMesh->_is_nil() )
158 SMESH::SMESH_subMesh_var aSubMesh = SMESH::SMESH_subMesh::_narrow(theIOR);
159 if( !aSubMesh->_is_nil() )
162 SMESH::SMESH_Hypothesis_var aHyp = SMESH::SMESH_Hypothesis::_narrow(theIOR);
163 if( !aHyp->_is_nil() )
166 SMESH::SMESH_GroupBase_var aGroup = SMESH::SMESH_GroupBase::_narrow(theIOR);
167 if( !aGroup->_is_nil() )
170 if(MYDEBUG) MESSAGE("CanPublishInStudy--CANT");
174 //=======================================================================
175 //function : ObjectToSObject
177 //=======================================================================
179 SALOMEDS::SObject_ptr SMESH_Gen_i::ObjectToSObject(SALOMEDS::Study_ptr theStudy,
180 CORBA::Object_ptr theObject)
182 SALOMEDS::SObject_var aSO;
183 if ( !CORBA::is_nil( theStudy ) && !CORBA::is_nil( theObject ))
185 CORBA::String_var objStr = SMESH_Gen_i::GetORB()->object_to_string( theObject );
186 aSO = theStudy->FindObjectIOR( objStr.in() );
191 //=======================================================================
192 //function : objectToServant
194 //=======================================================================
196 template<typename T> static inline T* objectToServant( CORBA::Object_ptr theIOR )
198 return dynamic_cast<T*>( SMESH_Gen_i::GetServant( theIOR ).in() );
201 //=======================================================================
202 //function : ShapeToGeomObject
204 //=======================================================================
206 GEOM::GEOM_Object_ptr SMESH_Gen_i::ShapeToGeomObject (const TopoDS_Shape& theShape )
208 GEOM::GEOM_Object_var aShapeObj;
209 if ( !theShape.IsNull() ) {
210 GEOM_Client* aClient = GetShapeReader();
211 TCollection_AsciiString IOR;
212 if ( aClient && aClient->Find( theShape, IOR ))
213 aShapeObj = GEOM::GEOM_Object::_narrow
214 ( GetORB()->string_to_object( IOR.ToCString() ) );
216 return aShapeObj._retn();
219 //=======================================================================
220 //function : GeomObjectToShape
222 //=======================================================================
224 TopoDS_Shape SMESH_Gen_i::GeomObjectToShape(GEOM::GEOM_Object_ptr theGeomObject)
227 if ( !theGeomObject->_is_nil() ) {
228 GEOM_Client* aClient = GetShapeReader();
229 GEOM::GEOM_Gen_ptr aGeomEngine = GetGeomEngine();
230 if ( aClient && !aGeomEngine->_is_nil () )
231 S = aClient->GetShape( aGeomEngine, theGeomObject );
236 //=======================================================================
239 //=======================================================================
241 static SALOMEDS::SObject_ptr publish(SALOMEDS::Study_ptr theStudy,
242 CORBA::Object_ptr theIOR,
243 SALOMEDS::SObject_ptr theFatherObject,
244 const int theTag = 0,
245 const char* thePixMap = 0,
246 const bool theSelectable = true)
248 SALOMEDS::SObject_var SO = SMESH_Gen_i::ObjectToSObject( theStudy, theIOR );
249 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
250 if ( SO->_is_nil() ) {
252 SO = aStudyBuilder->NewObject( theFatherObject );
253 else if ( !theFatherObject->FindSubObject( theTag, SO ))
254 SO = aStudyBuilder->NewObjectToTag( theFatherObject, theTag );
257 SALOMEDS::GenericAttribute_var anAttr;
258 if ( !CORBA::is_nil( theIOR )) {
259 anAttr = aStudyBuilder->FindOrCreateAttribute( SO, "AttributeIOR" );
260 CORBA::String_var objStr = SMESH_Gen_i::GetORB()->object_to_string( theIOR );
261 SALOMEDS::AttributeIOR::_narrow(anAttr)->SetValue( objStr.in() );
264 anAttr = aStudyBuilder->FindOrCreateAttribute( SO, "AttributePixMap" );
265 SALOMEDS::AttributePixMap::_narrow( anAttr )->SetPixMap( thePixMap );
267 if ( !theSelectable ) {
268 anAttr = aStudyBuilder->FindOrCreateAttribute( SO, "AttributeSelectable" );
269 SALOMEDS::AttributeSelectable::_narrow( anAttr )->SetSelectable( false );
274 //=======================================================================
277 //=======================================================================
279 void SMESH_Gen_i::SetName(SALOMEDS::SObject_ptr theSObject,
281 const char* theDefaultName)
283 if ( !theSObject->_is_nil() ) {
284 SALOMEDS::StudyBuilder_var aStudyBuilder = theSObject->GetStudy()->NewBuilder();
285 SALOMEDS::GenericAttribute_var anAttr =
286 aStudyBuilder->FindOrCreateAttribute( theSObject, "AttributeName" );
287 SALOMEDS::AttributeName_var aNameAttr = SALOMEDS::AttributeName::_narrow( anAttr );
288 if ( theName && strlen( theName ) != 0 )
289 aNameAttr->SetValue( theName );
291 CORBA::String_var curName = CORBA::string_dup( aNameAttr->Value() );
292 if ( strlen( curName ) == 0 ) {
293 TCollection_AsciiString aName( (char*) theDefaultName );
294 aName += TCollection_AsciiString("_") + TCollection_AsciiString( theSObject->Tag() );
295 aNameAttr->SetValue( aName.ToCString() );
301 //=======================================================================
302 //function : SetPixMap
304 //=======================================================================
306 void SMESH_Gen_i::SetPixMap(SALOMEDS::SObject_ptr theSObject,
307 const char* thePixMap)
309 if ( !theSObject->_is_nil() && thePixMap && strlen( thePixMap ))
311 SALOMEDS::Study_var aStudy = theSObject->GetStudy();
312 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
313 SALOMEDS::GenericAttribute_var anAttr =
314 aStudyBuilder->FindOrCreateAttribute( theSObject, "AttributePixMap" );
315 SALOMEDS::AttributePixMap_var aPMAttr = SALOMEDS::AttributePixMap::_narrow( anAttr );
316 aPMAttr->SetPixMap( thePixMap );
320 //=======================================================================
321 //function : addReference
323 //=======================================================================
325 static void addReference (SALOMEDS::Study_ptr theStudy,
326 SALOMEDS::SObject_ptr theSObject,
327 CORBA::Object_ptr theToObject,
330 SALOMEDS::SObject_var aToObjSO = SMESH_Gen_i::ObjectToSObject( theStudy, theToObject );
331 if ( !aToObjSO->_is_nil() && !theSObject->_is_nil() ) {
332 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
333 SALOMEDS::SObject_var aReferenceSO;
335 // check if the reference to theToObject already exists
336 // and find a free label for the reference object
337 bool isReferred = false;
339 SALOMEDS::ChildIterator_var anIter = theStudy->NewChildIterator( theSObject );
340 for ( ; !isReferred && anIter->More(); anIter->Next(), ++tag ) {
341 if ( anIter->Value()->ReferencedObject( aReferenceSO )) {
342 if ( strcmp( aReferenceSO->GetID(), aToObjSO->GetID() ) == 0 )
345 else if ( !theTag ) {
346 SALOMEDS::GenericAttribute_var anAttr;
347 if ( !anIter->Value()->FindAttribute( anAttr, "AttributeIOR" ))
356 if ( !theSObject->FindSubObject( theTag, aReferenceSO ))
357 aReferenceSO = aStudyBuilder->NewObjectToTag( theSObject, theTag );
358 aStudyBuilder->Addreference( aReferenceSO, aToObjSO );
362 //=============================================================================
364 * SMESH_Gen_i::PublishInStudy
366 * Publish object in the study
368 //=============================================================================
370 SALOMEDS::SObject_ptr SMESH_Gen_i::PublishInStudy(SALOMEDS::Study_ptr theStudy,
371 SALOMEDS::SObject_ptr theSObject,
372 CORBA::Object_ptr theIOR,
374 throw (SALOME::SALOME_Exception)
376 Unexpect aCatch(SALOME_SalomeException);
377 SALOMEDS::SObject_var aSO;
378 if ( CORBA::is_nil( theStudy ) || CORBA::is_nil( theIOR ))
380 if(MYDEBUG) MESSAGE("PublishInStudy");
383 SMESH::SMESH_Mesh_var aMesh = SMESH::SMESH_Mesh::_narrow( theIOR );
384 if( !aMesh->_is_nil() )
385 aSO = PublishMesh( theStudy, aMesh, theName );
387 // Publishing a sub-mesh
388 SMESH::SMESH_subMesh_var aSubMesh = SMESH::SMESH_subMesh::_narrow( theIOR );
389 if( aSO->_is_nil() && !aSubMesh->_is_nil() ) {
390 GEOM::GEOM_Object_var aShapeObject = aSubMesh->GetSubShape();
391 aMesh = aSubMesh->GetFather();
392 aSO = PublishSubMesh( theStudy, aMesh, aSubMesh, aShapeObject, theName );
395 // Publishing a hypothesis or algorithm
396 SMESH::SMESH_Hypothesis_var aHyp = SMESH::SMESH_Hypothesis::_narrow( theIOR );
397 if ( aSO->_is_nil() && !aHyp->_is_nil() )
398 aSO = PublishHypothesis( theStudy, aHyp );
400 // Publishing a group
401 SMESH::SMESH_GroupBase_var aGroup = SMESH::SMESH_GroupBase::_narrow(theIOR);
402 if ( aSO->_is_nil() && !aGroup->_is_nil() ) {
403 GEOM::GEOM_Object_var aShapeObject;
404 aMesh = aGroup->GetMesh();
405 aSO = PublishGroup( theStudy, aMesh, aGroup, aShapeObject, theName );
407 if(MYDEBUG) MESSAGE("PublishInStudy_END");
412 //=======================================================================
413 //function : PublishComponent
415 //=======================================================================
417 SALOMEDS::SComponent_ptr SMESH_Gen_i::PublishComponent(SALOMEDS::Study_ptr theStudy)
419 if ( CORBA::is_nil( theStudy ))
420 return SALOMEDS::SComponent::_nil();
421 if(MYDEBUG) MESSAGE("PublishComponent");
423 SALOMEDS::SComponent_var father =
424 SALOMEDS::SComponent::_narrow( theStudy->FindComponent( ComponentDataType() ) );
425 if ( !CORBA::is_nil( father ) )
426 return father._retn();
428 SALOME_ModuleCatalog::ModuleCatalog_var aCat =
429 SALOME_ModuleCatalog::ModuleCatalog::_narrow( GetNS()->Resolve("/Kernel/ModulCatalog") );
430 if ( CORBA::is_nil( aCat ) )
431 return father._retn();
433 SALOME_ModuleCatalog::Acomponent_var aComp = aCat->GetComponent( ComponentDataType() );
434 if ( CORBA::is_nil( aComp ) )
435 return father._retn();
437 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
438 SALOMEDS::GenericAttribute_var anAttr;
439 SALOMEDS::AttributePixMap_var aPixmap;
441 father = aStudyBuilder->NewComponent( ComponentDataType() );
442 aStudyBuilder->DefineComponentInstance( father, SMESH_Gen::_this() );
443 anAttr = aStudyBuilder->FindOrCreateAttribute( father, "AttributePixMap" );
444 aPixmap = SALOMEDS::AttributePixMap::_narrow( anAttr );
445 aPixmap ->SetPixMap( "ICON_OBJBROWSER_SMESH" );
446 SetName( father, aComp->componentusername(), "MESH" );
447 if(MYDEBUG) MESSAGE("PublishComponent--END");
449 return father._retn();
452 //=============================================================================
454 * findMaxChildTag [ static internal ]
456 * Finds maximum child tag for the given object
458 //=============================================================================
460 static long findMaxChildTag( SALOMEDS::SObject_ptr theSObject )
463 if ( !theSObject->_is_nil() ) {
464 SALOMEDS::Study_var aStudy = theSObject->GetStudy();
465 if ( !aStudy->_is_nil() ) {
466 SALOMEDS::ChildIterator_var anIter = aStudy->NewChildIterator( theSObject );
467 for ( ; anIter->More(); anIter->Next() ) {
468 long nTag = anIter->Value()->Tag();
477 //=======================================================================
478 //function : PublishMesh
480 //=======================================================================
482 SALOMEDS::SObject_ptr SMESH_Gen_i::PublishMesh (SALOMEDS::Study_ptr theStudy,
483 SMESH::SMESH_Mesh_ptr theMesh,
486 if ( CORBA::is_nil( theStudy ) ||
487 CORBA::is_nil( theMesh ))
488 return SALOMEDS::SComponent::_nil();
489 if(MYDEBUG) MESSAGE("PublishMesh--IN");
491 // find or publish a mesh
493 SALOMEDS::SObject_var aMeshSO = ObjectToSObject( theStudy, theMesh );
494 if ( aMeshSO->_is_nil() )
496 SALOMEDS::SComponent_var father = PublishComponent( theStudy );
497 if ( father->_is_nil() )
498 return aMeshSO._retn();
500 // Find correct free tag
501 long aTag = findMaxChildTag( father.in() );
502 if ( aTag <= GetAlgorithmsRootTag() )
503 aTag = GetAlgorithmsRootTag() + 1;
507 aMeshSO = publish (theStudy, theMesh, father, aTag, "ICON_SMESH_TREE_MESH_WARN" );
508 if ( aMeshSO->_is_nil() )
509 return aMeshSO._retn();
511 SetName( aMeshSO, theName, "Mesh" );
513 // Add shape reference
515 GEOM::GEOM_Object_var aShapeObject = theMesh->GetShapeToMesh();
516 if ( !CORBA::is_nil( aShapeObject )) {
517 addReference( theStudy, aMeshSO, aShapeObject, GetRefOnShapeTag() );
519 // Publish global hypotheses
521 SMESH::ListOfHypothesis * hypList = theMesh->GetHypothesisList( aShapeObject );
523 for ( int i = 0; i < hypList->length(); i++ ) {
524 SMESH::SMESH_Hypothesis_var aHyp = SMESH::SMESH_Hypothesis::_narrow( (*hypList)[ i ]);
525 PublishHypothesis( theStudy, aHyp );
526 AddHypothesisToShape( theStudy, theMesh, aShapeObject, aHyp );
532 SMESH_Mesh_i* mesh_i = objectToServant<SMESH_Mesh_i>( theMesh );
534 return aMeshSO._retn();
535 map<int, SMESH_subMesh_i*>& subMap = mesh_i->_mapSubMesh_i;
536 map<int, SMESH_subMesh_i*>::iterator subIt = subMap.begin();
537 for ( ; subIt != subMap.end(); subIt++ ) {
538 SMESH::SMESH_subMesh_ptr aSubMesh = (*subIt).second->_this();
539 if ( !CORBA::is_nil( aSubMesh )) {
540 aShapeObject = aSubMesh->GetSubShape();
541 PublishSubMesh( theStudy, theMesh, aSubMesh, aShapeObject );
546 const map<int, SMESH::SMESH_GroupBase_ptr>& grMap = mesh_i->getGroups();
547 map<int, SMESH::SMESH_GroupBase_ptr>::const_iterator it = grMap.begin();
548 for ( ; it != grMap.end(); it++ )
550 SMESH::SMESH_GroupBase_ptr aGroup = (*it).second;
551 if ( !aGroup->_is_nil() ) {
552 GEOM::GEOM_Object_var aShapeObj;
553 SMESH::SMESH_GroupOnGeom_var aGeomGroup =
554 SMESH::SMESH_GroupOnGeom::_narrow( aGroup );
555 if ( !aGeomGroup->_is_nil() )
556 aShapeObj = aGeomGroup->GetShape();
557 PublishGroup( theStudy, theMesh, aGroup, aShapeObj );
561 if(MYDEBUG) MESSAGE("PublishMesh_END");
562 return aMeshSO._retn();
565 //=======================================================================
566 //function : PublishSubMesh
568 //=======================================================================
570 SALOMEDS::SObject_ptr SMESH_Gen_i::PublishSubMesh (SALOMEDS::Study_ptr theStudy,
571 SMESH::SMESH_Mesh_ptr theMesh,
572 SMESH::SMESH_subMesh_ptr theSubMesh,
573 GEOM::GEOM_Object_ptr theShapeObject,
576 if (theStudy->_is_nil() || theMesh->_is_nil() ||
577 theSubMesh->_is_nil() || theShapeObject->_is_nil() )
578 return SALOMEDS::SObject::_nil();
580 SALOMEDS::SObject_var aSubMeshSO = ObjectToSObject( theStudy, theSubMesh );
581 if ( aSubMeshSO->_is_nil() )
583 SALOMEDS::SObject_var aMeshSO = ObjectToSObject( theStudy, theMesh );
584 if ( aMeshSO->_is_nil() ) {
585 aMeshSO = PublishMesh( theStudy, theMesh );
586 if ( aMeshSO->_is_nil())
587 return SALOMEDS::SObject::_nil();
589 // Find submesh sub-tree tag
591 char* aRootName = "";
592 switch ( theShapeObject->GetShapeType() ) {
594 aRootTag = GetSubMeshOnVertexTag();
595 aRootName = "SubMeshes on Vertex";
598 aRootTag = GetSubMeshOnEdgeTag();
599 aRootName = "SubMeshes on Edge";
602 aRootTag = GetSubMeshOnWireTag();
603 aRootName = "SubMeshes on Wire";
606 aRootTag = GetSubMeshOnFaceTag();
607 aRootName = "SubMeshes on Face";
610 aRootTag = GetSubMeshOnShellTag();
611 aRootName = "SubMeshes on Shell";
614 aRootTag = GetSubMeshOnSolidTag();
615 aRootName = "SubMeshes on Solid";
618 aRootTag = GetSubMeshOnCompoundTag();
619 aRootName = "SubMeshes on Compound";
623 // Find or create submesh root
624 SALOMEDS::SObject_var aRootSO = publish (theStudy, CORBA::Object::_nil(),
625 aMeshSO, aRootTag, 0, false );
626 SetName( aRootSO, aRootName );
628 // Add new submesh to corresponding sub-tree
629 aSubMeshSO = publish (theStudy, theSubMesh, aRootSO, 0, "ICON_SMESH_TREE_MESH_WARN");
630 if ( aSubMeshSO->_is_nil() )
631 return aSubMeshSO._retn();
633 SetName( aSubMeshSO, theName, "SubMesh" );
635 // Add reference to theShapeObject
637 addReference( theStudy, aSubMeshSO, theShapeObject, 1 );
639 // Publish hypothesis
641 SMESH::ListOfHypothesis * hypList = theMesh->GetHypothesisList( theShapeObject );
643 for ( int i = 0; i < hypList->length(); i++ ) {
644 SMESH::SMESH_Hypothesis_var aHyp = SMESH::SMESH_Hypothesis::_narrow( (*hypList)[ i ]);
645 PublishHypothesis( theStudy, aHyp );
646 AddHypothesisToShape( theStudy, theMesh, theShapeObject, aHyp );
649 return aSubMeshSO._retn();
652 //=======================================================================
653 //function : PublishGroup
655 //=======================================================================
657 SALOMEDS::SObject_ptr SMESH_Gen_i::PublishGroup (SALOMEDS::Study_ptr theStudy,
658 SMESH::SMESH_Mesh_ptr theMesh,
659 SMESH::SMESH_GroupBase_ptr theGroup,
660 GEOM::GEOM_Object_ptr theShapeObject,
663 if (theStudy->_is_nil() || theMesh->_is_nil() || theGroup->_is_nil() )
664 return SALOMEDS::SObject::_nil();
666 SALOMEDS::SObject_var aGroupSO = ObjectToSObject( theStudy, theGroup );
667 if ( aGroupSO->_is_nil() )
669 SALOMEDS::SObject_var aMeshSO = ObjectToSObject( theStudy, theMesh );
670 if ( aMeshSO->_is_nil() ) {
671 aMeshSO = PublishInStudy( theStudy, SALOMEDS::SObject::_nil(), theMesh, "");
672 if ( aMeshSO->_is_nil())
673 return SALOMEDS::SObject::_nil();
675 int aType = (int)theGroup->GetType();
676 const char* aRootNames[] = {
677 "Compound Groups", "Groups of Nodes",
678 "Groups of Edges", "Groups of Faces", "Groups of Volumes" };
680 // Currently, groups with heterogenous content are not supported
681 if ( aType != SMESH::ALL ) {
682 long aRootTag = GetNodeGroupsTag() + aType - 1;
684 // Find or create groups root
685 SALOMEDS::SObject_var aRootSO = publish (theStudy, CORBA::Object::_nil(),
686 aMeshSO, aRootTag, 0, false );
688 SetName( aRootSO, aRootNames[aType] );
690 // Add new group to corresponding sub-tree
691 aGroupSO = publish (theStudy, theGroup, aRootSO, 0, "ICON_SMESH_TREE_GROUP" );
693 if ( aGroupSO->_is_nil() )
694 return aGroupSO._retn();
697 SetName( aGroupSO, theName, "Group" );
699 //Add reference to geometry
700 if ( !theShapeObject->_is_nil() )
701 addReference( theStudy, aGroupSO, theShapeObject, 1 );
703 return aGroupSO._retn();
706 //=======================================================================
707 //function : PublishHypothesis
709 //=======================================================================
711 SALOMEDS::SObject_ptr
712 SMESH_Gen_i::PublishHypothesis (SALOMEDS::Study_ptr theStudy,
713 SMESH::SMESH_Hypothesis_ptr theHyp,
716 if(MYDEBUG) MESSAGE("PublishHypothesis")
717 if (theStudy->_is_nil() || theHyp->_is_nil())
718 return SALOMEDS::SObject::_nil();
720 SALOMEDS::SObject_var aHypSO = ObjectToSObject( theStudy, theHyp );
721 if ( aHypSO->_is_nil() )
723 SALOMEDS::SComponent_var father = PublishComponent( theStudy );
724 if ( father->_is_nil() )
725 return aHypSO._retn();
727 //Find or Create Hypothesis root
728 bool isAlgo = ( !SMESH::SMESH_Algo::_narrow( theHyp )->_is_nil() );
729 int aRootTag = isAlgo ? GetAlgorithmsRootTag() : GetHypothesisRootTag();
730 SALOMEDS::SObject_var aRootSO =
731 publish (theStudy, CORBA::Object::_nil(),father, aRootTag,
732 isAlgo ? "ICON_SMESH_TREE_ALGO" : "ICON_SMESH_TREE_HYPO", false);
733 SetName( aRootSO, isAlgo ? "Algorithms" : "Hypotheses" );
735 // Add New Hypothesis
736 string aPmName = isAlgo ? "ICON_SMESH_TREE_ALGO_" : "ICON_SMESH_TREE_HYPO_";
737 aPmName += theHyp->GetName();
738 // prepend plugin name to pixmap name
739 string pluginName = myHypCreatorMap[string(theHyp->GetName())]->GetModuleName();
740 if ( pluginName != "StdMeshers" )
741 aPmName = pluginName + "::" + aPmName;
742 aHypSO = publish( theStudy, theHyp, aRootSO, 0, aPmName.c_str() );
745 if ( !aHypSO->_is_nil() ) {
746 CORBA::String_var aHypName = CORBA::string_dup( theHyp->GetName() );
747 SetName( aHypSO, theName, aHypName );
750 if(MYDEBUG) MESSAGE("PublishHypothesis--END")
751 return aHypSO._retn();
754 //=======================================================================
755 //function : GetMeshOrSubmeshByShape
757 //=======================================================================
759 SALOMEDS::SObject_ptr
760 SMESH_Gen_i::GetMeshOrSubmeshByShape (SALOMEDS::Study_ptr theStudy,
761 SMESH::SMESH_Mesh_ptr theMesh,
762 GEOM::GEOM_Object_ptr theShape)
764 if(MYDEBUG) MESSAGE("GetMeshOrSubmeshByShape")
765 SALOMEDS::SObject_var aMeshOrSubMesh;
766 if (theMesh->_is_nil() || ( theShape->_is_nil() && theMesh->HasShapeToMesh()))
767 return aMeshOrSubMesh._retn();
770 if(theMesh->HasShapeToMesh())
771 aShape = GeomObjectToShape( theShape );
773 aShape = SMESH_Mesh::PseudoShape();
775 SMESH_Mesh_i* mesh_i = objectToServant<SMESH_Mesh_i>( theMesh );
777 if ( !aShape.IsNull() && mesh_i && mesh_i->GetImpl().GetMeshDS() ) {
778 SMESHDS_Mesh* meshDS = mesh_i->GetImpl().GetMeshDS();
779 if ( aShape.IsSame( meshDS->ShapeToMesh() ))
780 aMeshOrSubMesh = ObjectToSObject( theStudy, theMesh );
782 int shapeID = meshDS->ShapeToIndex( aShape );
783 SMESH::SMESH_subMesh_var aSubMesh = mesh_i->getSubMesh(shapeID);
784 if ( !aSubMesh->_is_nil() )
785 aMeshOrSubMesh = ObjectToSObject( theStudy, aSubMesh );
788 if(MYDEBUG) MESSAGE("GetMeshOrSubmeshByShape--END")
789 return aMeshOrSubMesh._retn();
792 //=======================================================================
793 //function : AddHypothesisToShape
795 //=======================================================================
797 bool SMESH_Gen_i::AddHypothesisToShape(SALOMEDS::Study_ptr theStudy,
798 SMESH::SMESH_Mesh_ptr theMesh,
799 GEOM::GEOM_Object_ptr theShape,
800 SMESH::SMESH_Hypothesis_ptr theHyp)
802 if(MYDEBUG) MESSAGE("AddHypothesisToShape")
803 if (theStudy->_is_nil() || theMesh->_is_nil() ||
804 theHyp->_is_nil() || (theShape->_is_nil()
805 && theMesh->HasShapeToMesh()) )
808 SALOMEDS::SObject_var aMeshSO = ObjectToSObject( theStudy, theMesh );
809 if ( aMeshSO->_is_nil() )
810 aMeshSO = PublishMesh( theStudy, theMesh );
811 SALOMEDS::SObject_var aHypSO = PublishHypothesis( theStudy, theHyp );
812 if ( aMeshSO->_is_nil() || aHypSO->_is_nil())
815 // Find a mesh or submesh refering to theShape
816 SALOMEDS::SObject_var aMeshOrSubMesh =
817 GetMeshOrSubmeshByShape( theStudy, theMesh, theShape );
818 if ( aMeshOrSubMesh->_is_nil() )
821 TopoDS_Shape aShape = GeomObjectToShape( theShape );
822 SMESH_Mesh_i* mesh_i = objectToServant<SMESH_Mesh_i>( theMesh );
823 if ( !aShape.IsNull() && mesh_i && mesh_i->GetImpl().GetMeshDS() ) {
824 SMESHDS_Mesh* meshDS = mesh_i->GetImpl().GetMeshDS();
825 int shapeID = meshDS->ShapeToIndex( aShape );
826 SMESH::SMESH_subMesh_var aSubMesh = mesh_i->getSubMesh(shapeID);
827 aMeshOrSubMesh = PublishSubMesh( theStudy, theMesh, aSubMesh, theShape );
829 if ( aMeshOrSubMesh->_is_nil() )
833 //Find or Create Applied Hypothesis root
834 bool aIsAlgo = !SMESH::SMESH_Algo::_narrow( theHyp )->_is_nil();
835 SALOMEDS::SObject_var AHR =
836 publish (theStudy, CORBA::Object::_nil(), aMeshOrSubMesh,
837 aIsAlgo ? GetRefOnAppliedAlgorithmsTag() : GetRefOnAppliedHypothesisTag(),
838 aIsAlgo ? "ICON_SMESH_TREE_ALGO" : "ICON_SMESH_TREE_HYPO", false);
839 SetName( AHR, aIsAlgo ? "Applied algorithms" : "Applied hypotheses" );
840 if ( AHR->_is_nil() )
843 addReference( theStudy, AHR, theHyp );
844 if(MYDEBUG) MESSAGE("AddHypothesisToShape--END")
848 //=======================================================================
849 //function : RemoveHypothesisFromShape
851 //=======================================================================
853 bool SMESH_Gen_i::RemoveHypothesisFromShape(SALOMEDS::Study_ptr theStudy,
854 SMESH::SMESH_Mesh_ptr theMesh,
855 GEOM::GEOM_Object_ptr theShape,
856 SMESH::SMESH_Hypothesis_ptr theHyp)
858 if (theStudy->_is_nil() || theMesh->_is_nil() ||
859 theHyp->_is_nil() || (theShape->_is_nil()
860 && theMesh->HasShapeToMesh()))
863 SALOMEDS::SObject_var aHypSO = ObjectToSObject( theStudy, theHyp );
864 if ( aHypSO->_is_nil() )
867 // Find a mesh or submesh refering to theShape
868 SALOMEDS::SObject_var aMeshOrSubMesh =
869 GetMeshOrSubmeshByShape( theStudy, theMesh, theShape );
870 if ( aMeshOrSubMesh->_is_nil() )
873 // Find and remove a reference to aHypSO
874 SALOMEDS::SObject_var aRef, anObj;
875 CORBA::String_var anID = CORBA::string_dup( aHypSO->GetID() );
876 SALOMEDS::ChildIterator_var it = theStudy->NewChildIterator( aMeshOrSubMesh );
877 for ( it->InitEx( true ); it->More(); it->Next() ) {
879 if (anObj->ReferencedObject( aRef ) && strcmp( aRef->GetID(), anID ) == 0 ) {
880 theStudy->NewBuilder()->RemoveObject( anObj );
887 //=======================================================================
888 //function : UpdateParameters
890 //=======================================================================
891 void SMESH_Gen_i::UpdateParameters(CORBA::Object_ptr theObject, const char* theParameters)
895 cout<<"UpdateParameters : "<<theParameters<<endl;
896 SALOMEDS::Study_ptr aStudy = GetCurrentStudy();
897 if(aStudy->_is_nil() || CORBA::is_nil(theObject))
900 SALOMEDS::SObject_var aSObj = ObjectToSObject(aStudy,theObject);
904 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
906 SALOMEDS::GenericAttribute_var aFindAttr;
907 bool hasAttr = aSObj->FindAttribute(aFindAttr, "AttributeString");
909 cout<<"Find Attribute "<<hasAttr<<endl;
911 SALOMEDS::GenericAttribute_var anAttr;
912 anAttr = aStudyBuilder->FindOrCreateAttribute( aSObj, "AttributeString");
913 SALOMEDS::AttributeString_var aStringAttr = SALOMEDS::AttributeString::_narrow(anAttr);
915 TCollection_AsciiString aNewParams;
916 TCollection_AsciiString aOldParameters(aStringAttr->Value());
917 TCollection_AsciiString anInputParams(ParseParameters(theParameters));
920 aNewParams = anInputParams;
922 aNewParams = aOldParameters+"|"+anInputParams;
926 cout<<"Input Parameters : "<<anInputParams<<endl;
927 cout<<"Old Parameters : "<<aOldParameters<<endl;
928 cout<<"New Parameters : "<<aNewParams<<endl;
932 aStringAttr->SetValue( aNewParams.ToCString() );
935 //=======================================================================
936 //function : ParseParameters
938 //=======================================================================
939 char* SMESH_Gen_i::ParseParameters(const char* theParameters)
941 const char* aParameters = CORBA::string_dup(theParameters);
942 TCollection_AsciiString anInputParams;
943 SALOMEDS::Study_ptr aStudy = GetCurrentStudy();
944 if( !aStudy->_is_nil() ) {
945 SALOMEDS::ListOfListOfStrings_var aSections = aStudy->ParseVariables(aParameters);
946 for(int j=0;j<aSections->length();j++) {
947 SALOMEDS::ListOfStrings aVars= aSections[j];
948 for(int i=0;i<aVars.length();i++ ) {
949 anInputParams += aStudy->IsVariable(aVars[i].in()) ?
950 TCollection_AsciiString(aVars[i].in()) : TCollection_AsciiString("");
951 if(i != aVars.length()-1)
954 if(j!=aSections->length()-1)
958 return CORBA::string_dup(anInputParams.ToCString());
961 //=======================================================================
962 //function : GetParameters
964 //=======================================================================
965 char* SMESH_Gen_i::GetParameters(CORBA::Object_ptr theObject)
967 TCollection_AsciiString aResult;
969 SALOMEDS::Study_ptr aStudy = GetCurrentStudy();
970 SALOMEDS::SObject_var aSObj = ObjectToSObject(aStudy,theObject);
972 if(!aStudy->_is_nil() &&
973 !CORBA::is_nil(theObject) &&
976 SALOMEDS::GenericAttribute_var anAttr;
977 if ( aSObj->FindAttribute(anAttr, "AttributeString")) {
978 aResult = TCollection_AsciiString(SALOMEDS::AttributeString::_narrow(anAttr)->Value());
982 return CORBA::string_dup( aResult.ToCString() );