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 //=============================================================================
143 * SMESH_Gen_i::CanPublishInStudy
145 * Returns true if object can be published in the study
147 //=============================================================================
149 bool SMESH_Gen_i::CanPublishInStudy(CORBA::Object_ptr theIOR)
151 if(MYDEBUG) MESSAGE("CanPublishInStudy - "<<!CORBA::is_nil(myCurrentStudy));
152 if(CORBA::is_nil(myCurrentStudy))
155 SMESH::SMESH_Mesh_var aMesh = SMESH::SMESH_Mesh::_narrow(theIOR);
156 if( !aMesh->_is_nil() )
159 SMESH::SMESH_subMesh_var aSubMesh = SMESH::SMESH_subMesh::_narrow(theIOR);
160 if( !aSubMesh->_is_nil() )
163 SMESH::SMESH_Hypothesis_var aHyp = SMESH::SMESH_Hypothesis::_narrow(theIOR);
164 if( !aHyp->_is_nil() )
167 SMESH::SMESH_GroupBase_var aGroup = SMESH::SMESH_GroupBase::_narrow(theIOR);
168 if( !aGroup->_is_nil() )
171 if(MYDEBUG) MESSAGE("CanPublishInStudy--CANT");
175 //=======================================================================
176 //function : ObjectToSObject
178 //=======================================================================
180 SALOMEDS::SObject_ptr SMESH_Gen_i::ObjectToSObject(SALOMEDS::Study_ptr theStudy,
181 CORBA::Object_ptr theObject)
183 SALOMEDS::SObject_var aSO;
184 if ( !CORBA::is_nil( theStudy ) && !CORBA::is_nil( theObject ))
186 CORBA::String_var objStr = SMESH_Gen_i::GetORB()->object_to_string( theObject );
187 aSO = theStudy->FindObjectIOR( objStr.in() );
192 //=======================================================================
193 //function : objectToServant
195 //=======================================================================
197 template<typename T> static inline T* objectToServant( CORBA::Object_ptr theIOR )
199 return dynamic_cast<T*>( SMESH_Gen_i::GetServant( theIOR ).in() );
202 //=======================================================================
203 //function : ShapeToGeomObject
205 //=======================================================================
207 GEOM::GEOM_Object_ptr SMESH_Gen_i::ShapeToGeomObject (const TopoDS_Shape& theShape )
209 GEOM::GEOM_Object_var aShapeObj;
210 if ( !theShape.IsNull() ) {
211 GEOM_Client* aClient = GetShapeReader();
212 TCollection_AsciiString IOR;
213 if ( aClient && aClient->Find( theShape, IOR ))
215 CORBA::Object_var obj = GetORB()->string_to_object( IOR.ToCString() );
216 aShapeObj = GEOM::GEOM_Object::_narrow ( obj );
219 return aShapeObj._retn();
222 //=======================================================================
223 //function : GeomObjectToShape
225 //=======================================================================
227 TopoDS_Shape SMESH_Gen_i::GeomObjectToShape(GEOM::GEOM_Object_ptr theGeomObject)
230 if ( !theGeomObject->_is_nil() ) {
231 GEOM_Client* aClient = GetShapeReader();
232 GEOM::GEOM_Gen_ptr aGeomEngine = GetGeomEngine();
233 if ( aClient && !aGeomEngine->_is_nil () )
234 S = aClient->GetShape( aGeomEngine, theGeomObject );
239 //=======================================================================
242 //=======================================================================
244 static SALOMEDS::SObject_ptr publish(SALOMEDS::Study_ptr theStudy,
245 CORBA::Object_ptr theIOR,
246 SALOMEDS::SObject_ptr theFatherObject,
247 const int theTag = 0,
248 const char* thePixMap = 0,
249 const bool theSelectable = true)
251 SALOMEDS::SObject_var SO = SMESH_Gen_i::ObjectToSObject( theStudy, theIOR );
252 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
253 if ( SO->_is_nil() ) {
255 SO = aStudyBuilder->NewObject( theFatherObject );
256 else if ( !theFatherObject->FindSubObject( theTag, SO ))
257 SO = aStudyBuilder->NewObjectToTag( theFatherObject, theTag );
260 SALOMEDS::GenericAttribute_var anAttr;
261 if ( !CORBA::is_nil( theIOR )) {
262 anAttr = aStudyBuilder->FindOrCreateAttribute( SO, "AttributeIOR" );
263 CORBA::String_var objStr = SMESH_Gen_i::GetORB()->object_to_string( theIOR );
264 SALOMEDS::AttributeIOR::_narrow(anAttr)->SetValue( objStr.in() );
267 anAttr = aStudyBuilder->FindOrCreateAttribute( SO, "AttributePixMap" );
268 SALOMEDS::AttributePixMap_var pm = SALOMEDS::AttributePixMap::_narrow( anAttr );
269 pm->SetPixMap( thePixMap );
271 if ( !theSelectable ) {
272 anAttr = aStudyBuilder->FindOrCreateAttribute( SO, "AttributeSelectable" );
273 SALOMEDS::AttributeSelectable::_narrow( anAttr )->SetSelectable( false );
278 //=======================================================================
281 //=======================================================================
283 void SMESH_Gen_i::SetName(SALOMEDS::SObject_ptr theSObject,
285 const char* theDefaultName)
287 if ( !theSObject->_is_nil() ) {
288 SALOMEDS::StudyBuilder_var aStudyBuilder = theSObject->GetStudy()->NewBuilder();
289 SALOMEDS::GenericAttribute_var anAttr =
290 aStudyBuilder->FindOrCreateAttribute( theSObject, "AttributeName" );
291 SALOMEDS::AttributeName_var aNameAttr = SALOMEDS::AttributeName::_narrow( anAttr );
292 if ( theName && strlen( theName ) != 0 )
293 aNameAttr->SetValue( theName );
295 CORBA::String_var curName = CORBA::string_dup( aNameAttr->Value() );
296 if ( strlen( curName ) == 0 ) {
297 TCollection_AsciiString aName( (char*) theDefaultName );
298 aName += TCollection_AsciiString("_") + TCollection_AsciiString( theSObject->Tag() );
299 aNameAttr->SetValue( aName.ToCString() );
305 //=======================================================================
306 //function : SetPixMap
308 //=======================================================================
310 void SMESH_Gen_i::SetPixMap(SALOMEDS::SObject_ptr theSObject,
311 const char* thePixMap)
313 if ( !theSObject->_is_nil() && thePixMap && strlen( thePixMap ))
315 SALOMEDS::Study_var aStudy = theSObject->GetStudy();
316 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
317 SALOMEDS::GenericAttribute_var anAttr =
318 aStudyBuilder->FindOrCreateAttribute( theSObject, "AttributePixMap" );
319 SALOMEDS::AttributePixMap_var aPMAttr = SALOMEDS::AttributePixMap::_narrow( anAttr );
320 aPMAttr->SetPixMap( thePixMap );
324 //=======================================================================
325 //function : addReference
327 //=======================================================================
329 static void addReference (SALOMEDS::Study_ptr theStudy,
330 SALOMEDS::SObject_ptr theSObject,
331 CORBA::Object_ptr theToObject,
334 SALOMEDS::SObject_var aToObjSO = SMESH_Gen_i::ObjectToSObject( theStudy, theToObject );
335 if ( !aToObjSO->_is_nil() && !theSObject->_is_nil() ) {
336 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
337 SALOMEDS::SObject_var aReferenceSO;
339 // check if the reference to theToObject already exists
340 // and find a free label for the reference object
341 bool isReferred = false;
343 SALOMEDS::ChildIterator_var anIter = theStudy->NewChildIterator( theSObject );
344 for ( ; !isReferred && anIter->More(); anIter->Next(), ++tag ) {
345 if ( anIter->Value()->ReferencedObject( aReferenceSO )) {
346 if ( strcmp( aReferenceSO->GetID(), aToObjSO->GetID() ) == 0 )
349 else if ( !theTag ) {
350 SALOMEDS::GenericAttribute_var anAttr;
351 if ( !anIter->Value()->FindAttribute( anAttr, "AttributeIOR" ))
360 if ( !theSObject->FindSubObject( theTag, aReferenceSO ))
361 aReferenceSO = aStudyBuilder->NewObjectToTag( theSObject, theTag );
362 aStudyBuilder->Addreference( aReferenceSO, aToObjSO );
366 //=============================================================================
368 * SMESH_Gen_i::PublishInStudy
370 * Publish object in the study
372 //=============================================================================
374 SALOMEDS::SObject_ptr SMESH_Gen_i::PublishInStudy(SALOMEDS::Study_ptr theStudy,
375 SALOMEDS::SObject_ptr theSObject,
376 CORBA::Object_ptr theIOR,
378 throw (SALOME::SALOME_Exception)
380 Unexpect aCatch(SALOME_SalomeException);
381 SALOMEDS::SObject_var aSO;
382 if ( CORBA::is_nil( theStudy ) || CORBA::is_nil( theIOR ))
384 if(MYDEBUG) MESSAGE("PublishInStudy");
387 SMESH::SMESH_Mesh_var aMesh = SMESH::SMESH_Mesh::_narrow( theIOR );
388 if( !aMesh->_is_nil() )
389 aSO = PublishMesh( theStudy, aMesh, theName );
391 // Publishing a sub-mesh
392 SMESH::SMESH_subMesh_var aSubMesh = SMESH::SMESH_subMesh::_narrow( theIOR );
393 if( aSO->_is_nil() && !aSubMesh->_is_nil() ) {
394 GEOM::GEOM_Object_var aShapeObject = aSubMesh->GetSubShape();
395 aMesh = aSubMesh->GetFather();
396 aSO = PublishSubMesh( theStudy, aMesh, aSubMesh, aShapeObject, theName );
399 // Publishing a hypothesis or algorithm
400 SMESH::SMESH_Hypothesis_var aHyp = SMESH::SMESH_Hypothesis::_narrow( theIOR );
401 if ( aSO->_is_nil() && !aHyp->_is_nil() )
402 aSO = PublishHypothesis( theStudy, aHyp );
404 // Publishing a group
405 SMESH::SMESH_GroupBase_var aGroup = SMESH::SMESH_GroupBase::_narrow(theIOR);
406 if ( aSO->_is_nil() && !aGroup->_is_nil() ) {
407 GEOM::GEOM_Object_var aShapeObject;
408 aMesh = aGroup->GetMesh();
409 aSO = PublishGroup( theStudy, aMesh, aGroup, aShapeObject, theName );
411 if(MYDEBUG) MESSAGE("PublishInStudy_END");
416 //=======================================================================
417 //function : PublishComponent
419 //=======================================================================
421 SALOMEDS::SComponent_ptr SMESH_Gen_i::PublishComponent(SALOMEDS::Study_ptr theStudy)
423 if ( CORBA::is_nil( theStudy ))
424 return SALOMEDS::SComponent::_nil();
425 if(MYDEBUG) MESSAGE("PublishComponent");
427 SALOMEDS::SComponent_var father =
428 SALOMEDS::SComponent::_narrow( theStudy->FindComponent( ComponentDataType() ) );
429 if ( !CORBA::is_nil( father ) )
430 return father._retn();
432 SALOME_ModuleCatalog::ModuleCatalog_var aCat =
433 SALOME_ModuleCatalog::ModuleCatalog::_narrow( GetNS()->Resolve("/Kernel/ModulCatalog") );
434 if ( CORBA::is_nil( aCat ) )
435 return father._retn();
437 SALOME_ModuleCatalog::Acomponent_var aComp = aCat->GetComponent( ComponentDataType() );
438 if ( CORBA::is_nil( aComp ) )
439 return father._retn();
441 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
442 SALOMEDS::GenericAttribute_var anAttr;
443 SALOMEDS::AttributePixMap_var aPixmap;
445 father = aStudyBuilder->NewComponent( ComponentDataType() );
446 aStudyBuilder->DefineComponentInstance( father, SMESH_Gen::_this() );
447 anAttr = aStudyBuilder->FindOrCreateAttribute( father, "AttributePixMap" );
448 aPixmap = SALOMEDS::AttributePixMap::_narrow( anAttr );
449 aPixmap ->SetPixMap( "ICON_OBJBROWSER_SMESH" );
450 SetName( father, aComp->componentusername(), "MESH" );
451 if(MYDEBUG) MESSAGE("PublishComponent--END");
453 return father._retn();
456 //=============================================================================
458 * findMaxChildTag [ static internal ]
460 * Finds maximum child tag for the given object
462 //=============================================================================
464 static long findMaxChildTag( SALOMEDS::SObject_ptr theSObject )
467 if ( !theSObject->_is_nil() ) {
468 SALOMEDS::Study_var aStudy = theSObject->GetStudy();
469 if ( !aStudy->_is_nil() ) {
470 SALOMEDS::ChildIterator_var anIter = aStudy->NewChildIterator( theSObject );
471 for ( ; anIter->More(); anIter->Next() ) {
472 long nTag = anIter->Value()->Tag();
481 //=======================================================================
482 //function : PublishMesh
484 //=======================================================================
486 SALOMEDS::SObject_ptr SMESH_Gen_i::PublishMesh (SALOMEDS::Study_ptr theStudy,
487 SMESH::SMESH_Mesh_ptr theMesh,
490 if ( CORBA::is_nil( theStudy ) ||
491 CORBA::is_nil( theMesh ))
492 return SALOMEDS::SComponent::_nil();
493 if(MYDEBUG) MESSAGE("PublishMesh--IN");
495 // find or publish a mesh
497 SALOMEDS::SObject_var aMeshSO = ObjectToSObject( theStudy, theMesh );
498 if ( aMeshSO->_is_nil() )
500 SALOMEDS::SComponent_var father = PublishComponent( theStudy );
501 if ( father->_is_nil() )
502 return aMeshSO._retn();
504 // Find correct free tag
505 long aTag = findMaxChildTag( father.in() );
506 if ( aTag <= GetAlgorithmsRootTag() )
507 aTag = GetAlgorithmsRootTag() + 1;
511 aMeshSO = publish (theStudy, theMesh, father, aTag, "ICON_SMESH_TREE_MESH_WARN" );
512 if ( aMeshSO->_is_nil() )
513 return aMeshSO._retn();
515 SetName( aMeshSO, theName, "Mesh" );
517 // Add shape reference
519 GEOM::GEOM_Object_var aShapeObject = theMesh->GetShapeToMesh();
520 if ( !CORBA::is_nil( aShapeObject )) {
521 addReference( theStudy, aMeshSO, aShapeObject, GetRefOnShapeTag() );
523 // Publish global hypotheses
525 SMESH::ListOfHypothesis_var hypList = theMesh->GetHypothesisList( aShapeObject );
526 for ( int i = 0; i < hypList->length(); i++ ) {
527 SMESH::SMESH_Hypothesis_var aHyp = SMESH::SMESH_Hypothesis::_narrow( hypList[ i ]);
528 PublishHypothesis( theStudy, aHyp );
529 AddHypothesisToShape( theStudy, theMesh, aShapeObject, aHyp );
535 SMESH_Mesh_i* mesh_i = objectToServant<SMESH_Mesh_i>( theMesh );
537 return aMeshSO._retn();
538 map<int, SMESH_subMesh_i*>& subMap = mesh_i->_mapSubMesh_i;
539 map<int, SMESH_subMesh_i*>::iterator subIt = subMap.begin();
540 for ( ; subIt != subMap.end(); subIt++ ) {
541 SMESH::SMESH_subMesh_ptr aSubMesh = (*subIt).second->_this();
542 if ( !CORBA::is_nil( aSubMesh )) {
543 aShapeObject = aSubMesh->GetSubShape();
544 PublishSubMesh( theStudy, theMesh, aSubMesh, aShapeObject );
549 const map<int, SMESH::SMESH_GroupBase_ptr>& grMap = mesh_i->getGroups();
550 map<int, SMESH::SMESH_GroupBase_ptr>::const_iterator it = grMap.begin();
551 for ( ; it != grMap.end(); it++ )
553 SMESH::SMESH_GroupBase_ptr aGroup = (*it).second;
554 if ( !aGroup->_is_nil() ) {
555 GEOM::GEOM_Object_var aShapeObj;
556 SMESH::SMESH_GroupOnGeom_var aGeomGroup =
557 SMESH::SMESH_GroupOnGeom::_narrow( aGroup );
558 if ( !aGeomGroup->_is_nil() )
559 aShapeObj = aGeomGroup->GetShape();
560 PublishGroup( theStudy, theMesh, aGroup, aShapeObj );
564 if(MYDEBUG) MESSAGE("PublishMesh_END");
565 return aMeshSO._retn();
568 //=======================================================================
569 //function : PublishSubMesh
571 //=======================================================================
573 SALOMEDS::SObject_ptr SMESH_Gen_i::PublishSubMesh (SALOMEDS::Study_ptr theStudy,
574 SMESH::SMESH_Mesh_ptr theMesh,
575 SMESH::SMESH_subMesh_ptr theSubMesh,
576 GEOM::GEOM_Object_ptr theShapeObject,
579 if (theStudy->_is_nil() || theMesh->_is_nil() ||
580 theSubMesh->_is_nil() || theShapeObject->_is_nil() )
581 return SALOMEDS::SObject::_nil();
583 SALOMEDS::SObject_var aSubMeshSO = ObjectToSObject( theStudy, theSubMesh );
584 if ( aSubMeshSO->_is_nil() )
586 SALOMEDS::SObject_var aMeshSO = ObjectToSObject( theStudy, theMesh );
587 if ( aMeshSO->_is_nil() ) {
588 aMeshSO = PublishMesh( theStudy, theMesh );
589 if ( aMeshSO->_is_nil())
590 return SALOMEDS::SObject::_nil();
592 // Find submesh sub-tree tag
594 const char* aRootName = "";
595 switch ( theShapeObject->GetShapeType() ) {
597 aRootTag = GetSubMeshOnVertexTag();
598 aRootName = "SubMeshes on Vertex";
601 aRootTag = GetSubMeshOnEdgeTag();
602 aRootName = "SubMeshes on Edge";
605 aRootTag = GetSubMeshOnWireTag();
606 aRootName = "SubMeshes on Wire";
609 aRootTag = GetSubMeshOnFaceTag();
610 aRootName = "SubMeshes on Face";
613 aRootTag = GetSubMeshOnShellTag();
614 aRootName = "SubMeshes on Shell";
617 aRootTag = GetSubMeshOnSolidTag();
618 aRootName = "SubMeshes on Solid";
621 aRootTag = GetSubMeshOnCompoundTag();
622 aRootName = "SubMeshes on Compound";
626 // Find or create submesh root
627 SALOMEDS::SObject_var aRootSO = publish (theStudy, CORBA::Object::_nil(),
628 aMeshSO, aRootTag, 0, false );
629 SetName( aRootSO, aRootName );
631 // Add new submesh to corresponding sub-tree
632 aSubMeshSO = publish (theStudy, theSubMesh, aRootSO, 0, "ICON_SMESH_TREE_MESH_WARN");
633 if ( aSubMeshSO->_is_nil() )
634 return aSubMeshSO._retn();
636 SetName( aSubMeshSO, theName, "SubMesh" );
638 // Add reference to theShapeObject
640 addReference( theStudy, aSubMeshSO, theShapeObject, 1 );
642 // Publish hypothesis
644 SMESH::ListOfHypothesis * hypList = theMesh->GetHypothesisList( theShapeObject );
646 for ( int i = 0; i < hypList->length(); i++ ) {
647 SMESH::SMESH_Hypothesis_var aHyp = SMESH::SMESH_Hypothesis::_narrow( (*hypList)[ i ]);
648 PublishHypothesis( theStudy, aHyp );
649 AddHypothesisToShape( theStudy, theMesh, theShapeObject, aHyp );
652 return aSubMeshSO._retn();
655 //=======================================================================
656 //function : PublishGroup
658 //=======================================================================
660 SALOMEDS::SObject_ptr SMESH_Gen_i::PublishGroup (SALOMEDS::Study_ptr theStudy,
661 SMESH::SMESH_Mesh_ptr theMesh,
662 SMESH::SMESH_GroupBase_ptr theGroup,
663 GEOM::GEOM_Object_ptr theShapeObject,
666 if (theStudy->_is_nil() || theMesh->_is_nil() || theGroup->_is_nil() )
667 return SALOMEDS::SObject::_nil();
669 SALOMEDS::SObject_var aGroupSO = ObjectToSObject( theStudy, theGroup );
670 if ( aGroupSO->_is_nil() )
672 SALOMEDS::SObject_var aMeshSO = ObjectToSObject( theStudy, theMesh );
673 if ( aMeshSO->_is_nil() ) {
674 aMeshSO = PublishInStudy( theStudy, SALOMEDS::SObject::_nil(), theMesh, "");
675 if ( aMeshSO->_is_nil())
676 return SALOMEDS::SObject::_nil();
678 int aType = (int)theGroup->GetType();
679 const char* aRootNames[] = {
680 "Compound Groups", "Groups of Nodes", "Groups of Edges",
681 "Groups of Faces", "Groups of Volumes", "Groups of 0D Elements" };
683 // Currently, groups with heterogenous content are not supported
684 if ( aType != SMESH::ALL ) {
685 long aRootTag = GetNodeGroupsTag() + aType - 1;
687 // Find or create groups root
688 SALOMEDS::SObject_var aRootSO = publish (theStudy, CORBA::Object::_nil(),
689 aMeshSO, aRootTag, 0, false );
691 SetName( aRootSO, aRootNames[aType] );
693 // Add new group to corresponding sub-tree
694 aGroupSO = publish (theStudy, theGroup, aRootSO, 0, "ICON_SMESH_TREE_GROUP" );
696 if ( aGroupSO->_is_nil() )
697 return aGroupSO._retn();
700 SetName( aGroupSO, theName, "Group" );
702 //Add reference to geometry
703 if ( !theShapeObject->_is_nil() )
704 addReference( theStudy, aGroupSO, theShapeObject, 1 );
706 return aGroupSO._retn();
709 //=======================================================================
710 //function : PublishHypothesis
712 //=======================================================================
714 SALOMEDS::SObject_ptr
715 SMESH_Gen_i::PublishHypothesis (SALOMEDS::Study_ptr theStudy,
716 SMESH::SMESH_Hypothesis_ptr theHyp,
719 if(MYDEBUG) MESSAGE("PublishHypothesis")
720 if (theStudy->_is_nil() || theHyp->_is_nil())
721 return SALOMEDS::SObject::_nil();
723 SALOMEDS::SObject_var aHypSO = ObjectToSObject( theStudy, theHyp );
724 if ( aHypSO->_is_nil() )
726 SALOMEDS::SComponent_var father = PublishComponent( theStudy );
727 if ( father->_is_nil() )
728 return aHypSO._retn();
730 //Find or Create Hypothesis root
731 bool isAlgo = ( !SMESH::SMESH_Algo::_narrow( theHyp )->_is_nil() );
732 int aRootTag = isAlgo ? GetAlgorithmsRootTag() : GetHypothesisRootTag();
733 SALOMEDS::SObject_var aRootSO =
734 publish (theStudy, CORBA::Object::_nil(),father, aRootTag,
735 isAlgo ? "ICON_SMESH_TREE_ALGO" : "ICON_SMESH_TREE_HYPO", false);
736 SetName( aRootSO, isAlgo ? "Algorithms" : "Hypotheses" );
738 // Add New Hypothesis
739 string aPmName = isAlgo ? "ICON_SMESH_TREE_ALGO_" : "ICON_SMESH_TREE_HYPO_";
740 aPmName += theHyp->GetName();
741 // prepend plugin name to pixmap name
742 string pluginName = myHypCreatorMap[string(theHyp->GetName())]->GetModuleName();
743 if ( pluginName != "StdMeshers" )
744 aPmName = pluginName + "::" + aPmName;
745 aHypSO = publish( theStudy, theHyp, aRootSO, 0, aPmName.c_str() );
748 if ( !aHypSO->_is_nil() ) {
749 CORBA::String_var aHypName = CORBA::string_dup( theHyp->GetName() );
750 SetName( aHypSO, theName, aHypName );
753 if(MYDEBUG) MESSAGE("PublishHypothesis--END")
754 return aHypSO._retn();
757 //=======================================================================
758 //function : GetMeshOrSubmeshByShape
760 //=======================================================================
762 SALOMEDS::SObject_ptr
763 SMESH_Gen_i::GetMeshOrSubmeshByShape (SALOMEDS::Study_ptr theStudy,
764 SMESH::SMESH_Mesh_ptr theMesh,
765 GEOM::GEOM_Object_ptr theShape)
767 if(MYDEBUG) MESSAGE("GetMeshOrSubmeshByShape")
768 SALOMEDS::SObject_var aMeshOrSubMesh;
769 if (theMesh->_is_nil() || ( theShape->_is_nil() && theMesh->HasShapeToMesh()))
770 return aMeshOrSubMesh._retn();
773 if(theMesh->HasShapeToMesh())
774 aShape = GeomObjectToShape( theShape );
776 aShape = SMESH_Mesh::PseudoShape();
778 SMESH_Mesh_i* mesh_i = objectToServant<SMESH_Mesh_i>( theMesh );
780 if ( !aShape.IsNull() && mesh_i && mesh_i->GetImpl().GetMeshDS() ) {
781 SMESHDS_Mesh* meshDS = mesh_i->GetImpl().GetMeshDS();
782 if ( aShape.IsSame( meshDS->ShapeToMesh() ))
783 aMeshOrSubMesh = ObjectToSObject( theStudy, theMesh );
785 int shapeID = meshDS->ShapeToIndex( aShape );
786 SMESH::SMESH_subMesh_var aSubMesh = mesh_i->getSubMesh(shapeID);
787 if ( !aSubMesh->_is_nil() )
788 aMeshOrSubMesh = ObjectToSObject( theStudy, aSubMesh );
791 if(MYDEBUG) MESSAGE("GetMeshOrSubmeshByShape--END")
792 return aMeshOrSubMesh._retn();
795 //=======================================================================
796 //function : AddHypothesisToShape
798 //=======================================================================
800 bool SMESH_Gen_i::AddHypothesisToShape(SALOMEDS::Study_ptr theStudy,
801 SMESH::SMESH_Mesh_ptr theMesh,
802 GEOM::GEOM_Object_ptr theShape,
803 SMESH::SMESH_Hypothesis_ptr theHyp)
805 if(MYDEBUG) MESSAGE("AddHypothesisToShape")
806 if (theStudy->_is_nil() || theMesh->_is_nil() ||
807 theHyp->_is_nil() || (theShape->_is_nil()
808 && theMesh->HasShapeToMesh()) )
811 SALOMEDS::SObject_var aMeshSO = ObjectToSObject( theStudy, theMesh );
812 if ( aMeshSO->_is_nil() )
813 aMeshSO = PublishMesh( theStudy, theMesh );
814 SALOMEDS::SObject_var aHypSO = PublishHypothesis( theStudy, theHyp );
815 if ( aMeshSO->_is_nil() || aHypSO->_is_nil())
818 // Find a mesh or submesh refering to theShape
819 SALOMEDS::SObject_var aMeshOrSubMesh =
820 GetMeshOrSubmeshByShape( theStudy, theMesh, theShape );
821 if ( aMeshOrSubMesh->_is_nil() )
824 TopoDS_Shape aShape = GeomObjectToShape( theShape );
825 SMESH_Mesh_i* mesh_i = objectToServant<SMESH_Mesh_i>( theMesh );
826 if ( !aShape.IsNull() && mesh_i && mesh_i->GetImpl().GetMeshDS() ) {
827 SMESHDS_Mesh* meshDS = mesh_i->GetImpl().GetMeshDS();
828 int shapeID = meshDS->ShapeToIndex( aShape );
829 SMESH::SMESH_subMesh_var aSubMesh = mesh_i->getSubMesh(shapeID);
830 aMeshOrSubMesh = PublishSubMesh( theStudy, theMesh, aSubMesh, theShape );
832 if ( aMeshOrSubMesh->_is_nil() )
836 //Find or Create Applied Hypothesis root
837 bool aIsAlgo = !SMESH::SMESH_Algo::_narrow( theHyp )->_is_nil();
838 SALOMEDS::SObject_var AHR =
839 publish (theStudy, CORBA::Object::_nil(), aMeshOrSubMesh,
840 aIsAlgo ? GetRefOnAppliedAlgorithmsTag() : GetRefOnAppliedHypothesisTag(),
841 aIsAlgo ? "ICON_SMESH_TREE_ALGO" : "ICON_SMESH_TREE_HYPO", false);
842 SetName( AHR, aIsAlgo ? "Applied algorithms" : "Applied hypotheses" );
843 if ( AHR->_is_nil() )
846 addReference( theStudy, AHR, theHyp );
847 if(MYDEBUG) MESSAGE("AddHypothesisToShape--END")
851 //=======================================================================
852 //function : RemoveHypothesisFromShape
854 //=======================================================================
856 bool SMESH_Gen_i::RemoveHypothesisFromShape(SALOMEDS::Study_ptr theStudy,
857 SMESH::SMESH_Mesh_ptr theMesh,
858 GEOM::GEOM_Object_ptr theShape,
859 SMESH::SMESH_Hypothesis_ptr theHyp)
861 if (theStudy->_is_nil() || theMesh->_is_nil() ||
862 theHyp->_is_nil() || (theShape->_is_nil()
863 && theMesh->HasShapeToMesh()))
866 SALOMEDS::SObject_var aHypSO = ObjectToSObject( theStudy, theHyp );
867 if ( aHypSO->_is_nil() )
870 // Find a mesh or submesh refering to theShape
871 SALOMEDS::SObject_var aMeshOrSubMesh =
872 GetMeshOrSubmeshByShape( theStudy, theMesh, theShape );
873 if ( aMeshOrSubMesh->_is_nil() )
876 // Find and remove a reference to aHypSO
877 SALOMEDS::SObject_var aRef, anObj;
878 CORBA::String_var anID = CORBA::string_dup( aHypSO->GetID() );
879 SALOMEDS::ChildIterator_var it = theStudy->NewChildIterator( aMeshOrSubMesh );
880 for ( it->InitEx( true ); it->More(); it->Next() ) {
882 if (anObj->ReferencedObject( aRef ) && strcmp( aRef->GetID(), anID ) == 0 ) {
883 theStudy->NewBuilder()->RemoveObject( anObj );
890 //=======================================================================
891 //function : UpdateParameters
893 //=======================================================================
894 void SMESH_Gen_i::UpdateParameters(CORBA::Object_ptr theObject, const char* theParameters)
898 cout<<"UpdateParameters : "<<theParameters<<endl;
899 SALOMEDS::Study_ptr aStudy = GetCurrentStudy();
900 if(aStudy->_is_nil() || CORBA::is_nil(theObject))
903 SALOMEDS::SObject_var aSObj = ObjectToSObject(aStudy,theObject);
907 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
909 SALOMEDS::GenericAttribute_var aFindAttr;
910 bool hasAttr = aSObj->FindAttribute(aFindAttr, "AttributeString");
912 cout<<"Find Attribute "<<hasAttr<<endl;
914 SALOMEDS::GenericAttribute_var anAttr;
915 anAttr = aStudyBuilder->FindOrCreateAttribute( aSObj, "AttributeString");
916 SALOMEDS::AttributeString_var aStringAttr = SALOMEDS::AttributeString::_narrow(anAttr);
918 CORBA::String_var oldparVar = aStringAttr->Value();
919 CORBA::String_var inpparVar = ParseParameters(theParameters);
920 TCollection_AsciiString aNewParams;
921 TCollection_AsciiString aOldParameters(oldparVar.inout());
922 TCollection_AsciiString anInputParams(inpparVar.inout());
924 aNewParams = anInputParams;
927 int pos = aOldParameters.SearchFromEnd("|");
929 TCollection_AsciiString previousParamFull(aOldParameters.Split(pos));
930 TCollection_AsciiString previousParam(previousParamFull);
931 TCollection_AsciiString theRepet("1");
932 pos = previousParam.SearchFromEnd(";*=");
935 theRepet = previousParam.Split(pos+2);
938 previousParam.Split(pos);
940 if(previousParam == anInputParams)
942 theRepet = theRepet.IntegerValue()+1;
943 aNewParams = aOldParameters + previousParam + ";*=" + theRepet;
947 aNewParams = aOldParameters + previousParamFull + "|" + anInputParams;
953 cout<<"Input Parameters : "<<anInputParams<<endl;
954 cout<<"Old Parameters : "<<aOldParameters<<endl;
955 cout<<"New Parameters : "<<aNewParams<<endl;
958 aStringAttr->SetValue( aNewParams.ToCString() );
961 //=======================================================================
962 //function : ParseParameters
964 //=======================================================================
965 char* SMESH_Gen_i::ParseParameters(const char* theParameters)
967 //const char* aParameters = theParameters;
968 // const char* aParameters = CORBA::string_dup(theParameters);
969 TCollection_AsciiString anInputParams;
970 SALOMEDS::Study_var aStudy = GetCurrentStudy();
971 if( !aStudy->_is_nil() ) {
972 // SALOMEDS::ListOfListOfStrings_var aSections = aStudy->ParseVariables(theParameters);
973 // for(int j=0;j<aSections->length();j++) {
974 // SALOMEDS::ListOfStrings aVars= aSections[j];
975 // for(int i=0;i<aVars.length();i++ ) {
976 // anInputParams += aStudy->IsVariable(aVars[i].in()) ?
977 // TCollection_AsciiString(aVars[i].in()) : TCollection_AsciiString("");
978 // if(i != aVars.length()-1)
979 // anInputParams+=":";
981 // if(j!=aSections->length()-1)
982 // anInputParams+="|";
984 TCollection_AsciiString paramStr( theParameters );
985 static TCollection_AsciiString separators(":|");
987 char sep, *pParams = (char*)paramStr.ToCString();
988 while ( beg < paramStr.Length() )
991 while ( ++end < paramStr.Length() )
992 if ( pParams[end] == ':' || pParams[end] == '|')
994 if ( end < paramStr.Length())
999 if ( aStudy->IsVariable( pParams+beg ))
1000 anInputParams += pParams+beg;
1001 if ( end < paramStr.Length() )
1002 anInputParams += sep;
1008 return CORBA::string_dup(anInputParams.ToCString());
1011 //=======================================================================
1012 //function : GetParameters
1014 //=======================================================================
1015 char* SMESH_Gen_i::GetParameters(CORBA::Object_ptr theObject)
1017 TCollection_AsciiString aResult;
1019 SALOMEDS::Study_ptr aStudy = GetCurrentStudy();
1020 SALOMEDS::SObject_var aSObj = ObjectToSObject(aStudy,theObject);
1022 if(!aStudy->_is_nil() &&
1023 !CORBA::is_nil(theObject) &&
1026 SALOMEDS::GenericAttribute_var anAttr;
1027 if ( aSObj->FindAttribute(anAttr, "AttributeString")) {
1028 aResult = TCollection_AsciiString(SALOMEDS::AttributeString::_narrow(anAttr)->Value());
1032 return CORBA::string_dup( aResult.ToCString() );