1 // Copyright (C) 2007-2021 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, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // File : SMESH_Gen_i_1.cxx
23 // Created : Thu Oct 21 17:24:06 2004
24 // Author : Edward AGAPOV (eap)
27 #include "SMESH_Gen_i.hxx"
29 #include "SMESHDS_Mesh.hxx"
30 #include "SMESH_Algo_i.hxx"
31 #include "SMESH_Comment.hxx"
32 #include "SMESH_Group_i.hxx"
33 #include "SMESH_Hypothesis_i.hxx"
34 #include "SMESH_Mesh_i.hxx"
35 #include "SMESH_subMesh_i.hxx"
37 #include <utilities.h>
38 #include <Utils_ExceptHandlers.hxx>
39 #include <SALOMEDS_wrap.hxx>
40 #include <SALOMEDS_Attributes_wrap.hxx>
41 #include "SALOME_KernelServices.hxx"
42 #include "SALOME_ModuleCatalog_impl.hxx"
44 #include <TCollection_AsciiString.hxx>
45 #include <TopoDS_Solid.hxx>
50 static int MYDEBUG = 0;
52 static int MYDEBUG = 0;
57 //=============================================================================
59 * Get...Tag [ static ]
61 * Methods which determine SMESH data model structure
63 //=============================================================================
65 long SMESH_Gen_i::GetHypothesisRootTag()
67 return SMESH::Tag_HypothesisRoot;
70 long SMESH_Gen_i::GetAlgorithmsRootTag()
72 return SMESH::Tag_AlgorithmsRoot;
75 long SMESH_Gen_i::GetRefOnShapeTag()
77 return SMESH::Tag_RefOnShape;
80 long SMESH_Gen_i::GetRefOnAppliedHypothesisTag()
82 return SMESH::Tag_RefOnAppliedHypothesis;
85 long SMESH_Gen_i::GetRefOnAppliedAlgorithmsTag()
87 return SMESH::Tag_RefOnAppliedAlgorithms;
90 long SMESH_Gen_i::GetSubMeshOnVertexTag()
92 return SMESH::Tag_SubMeshOnVertex;
95 long SMESH_Gen_i::GetSubMeshOnEdgeTag()
97 return SMESH::Tag_SubMeshOnEdge;
100 long SMESH_Gen_i::GetSubMeshOnFaceTag()
102 return SMESH::Tag_SubMeshOnFace;
105 long SMESH_Gen_i::GetSubMeshOnSolidTag()
107 return SMESH::Tag_SubMeshOnSolid;
110 long SMESH_Gen_i::GetSubMeshOnCompoundTag()
112 return SMESH::Tag_SubMeshOnCompound;
115 long SMESH_Gen_i::GetSubMeshOnWireTag()
117 return SMESH::Tag_SubMeshOnWire;
120 long SMESH_Gen_i::GetSubMeshOnShellTag()
122 return SMESH::Tag_SubMeshOnShell;
125 long SMESH_Gen_i::GetNodeGroupsTag()
127 return SMESH::Tag_NodeGroups;
130 long SMESH_Gen_i::GetEdgeGroupsTag()
132 return SMESH::Tag_EdgeGroups;
135 long SMESH_Gen_i::GetFaceGroupsTag()
137 return SMESH::Tag_FaceGroups;
140 long SMESH_Gen_i::GetVolumeGroupsTag()
142 return SMESH::Tag_VolumeGroups;
145 long SMESH_Gen_i::Get0DElementsGroupsTag()
147 return SMESH::Tag_0DElementsGroups;
150 long SMESH_Gen_i::GetBallElementsGroupsTag()
152 return SMESH::Tag_BallElementsGroups;
155 //=============================================================================
157 * SMESH_Gen_i::CanPublishInStudy
159 * Returns true if object can be published in the study
161 //=============================================================================
163 bool SMESH_Gen_i::CanPublishInStudy(CORBA::Object_ptr theIOR)
165 if(MYDEBUG) MESSAGE("CanPublishInStudy - "<<!CORBA::is_nil(getStudyServant()));
167 if ( !myIsEnablePublish )
170 SMESH::SMESH_Mesh_var aMesh = SMESH::SMESH_Mesh::_narrow(theIOR);
171 if( !aMesh->_is_nil() )
174 SMESH::SMESH_subMesh_var aSubMesh = SMESH::SMESH_subMesh::_narrow(theIOR);
175 if( !aSubMesh->_is_nil() )
178 SMESH::SMESH_Hypothesis_var aHyp = SMESH::SMESH_Hypothesis::_narrow(theIOR);
179 if( !aHyp->_is_nil() )
182 SMESH::SMESH_GroupBase_var aGroup = SMESH::SMESH_GroupBase::_narrow(theIOR);
183 if( !aGroup->_is_nil() )
186 if(MYDEBUG) MESSAGE("CanPublishInStudy--CANT");
190 //=======================================================================
191 //function : ObjectToSObject
192 //purpose : Put a result into a SALOMEDS::SObject_wrap or call UnRegister()!
193 //=======================================================================
195 SALOMEDS::SObject_ptr SMESH_Gen_i::ObjectToSObject(CORBA::Object_ptr theObject)
197 SALOMEDS::SObject_wrap aSO;
199 if ( !CORBA::is_nil( theObject ))
201 CORBA::String_var objStr = SMESH_Gen_i::GetORB()->object_to_string( theObject );
202 aSO = getStudyServant()->FindObjectIOR( objStr.in() );
211 //=======================================================================
212 //function : objectToServant
214 //=======================================================================
216 template<typename T> static inline T* objectToServant( CORBA::Object_ptr theIOR )
218 return dynamic_cast<T*>( SMESH_Gen_i::GetServant( theIOR ).in() );
221 //=======================================================================
222 //function : ShapeToGeomObject
224 //=======================================================================
226 GEOM::GEOM_Object_ptr SMESH_Gen_i::ShapeToGeomObject (const TopoDS_Shape& theShape )
228 GEOM::GEOM_Object_var aShapeObj;
229 if ( !theShape.IsNull() && mySMESHGen ) {
230 GEOM_Client* aClient = mySMESHGen->GetShapeReader();
231 TCollection_AsciiString IOR;
232 if ( aClient && aClient->Find( theShape, IOR ))
234 CORBA::Object_var obj = GetORB()->string_to_object( IOR.ToCString() );
235 if ( !obj->_non_existent() )
236 aShapeObj = GEOM::GEOM_Object::_narrow ( obj );
239 return aShapeObj._retn();
242 //=======================================================================
243 //function : GeomObjectToShape
245 //=======================================================================
247 TopoDS_Shape SMESH_Gen_i::GeomObjectToShape(GEOM::GEOM_Object_ptr theGeomObject)
250 if ( mySMESHGen && !theGeomObject->_is_nil() && !theGeomObject->_non_existent() )
252 GEOM_Client* aClient = mySMESHGen->GetShapeReader();
253 GEOM::GEOM_Gen_var aGeomEngine = GetGeomEngine( theGeomObject );
254 if ( aClient && !aGeomEngine->_is_nil () )
255 S = aClient->GetShape( aGeomEngine, theGeomObject );
260 //================================================================================
262 * \brief Get GEOM Object by its study entry
264 //================================================================================
266 GEOM::GEOM_Object_ptr SMESH_Gen_i::GetGeomObjectByEntry( const std::string& entry )
268 GEOM::GEOM_Object_var go;
269 if ( !entry.empty() && mySMESHGen )
271 SALOMEDS::SObject_wrap so = mySMESHGen->getStudyServant()->FindObjectID( entry.c_str() );
272 CORBA::Object_var obj = SObjectToObject( so );
273 go = GEOM::GEOM_Object::_narrow( obj );
279 //=======================================================================
282 //=======================================================================
284 SALOMEDS::SObject_ptr SMESH_Gen_i::publish(CORBA::Object_ptr theIOR,
285 SALOMEDS::SObject_ptr theFatherObject,
287 const char* thePixMap,
288 const bool theSelectable)
290 SALOMEDS::Study_var theStudy = getStudyServant();
291 SALOMEDS::SObject_wrap SO = ObjectToSObject( theIOR );
292 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
293 SALOMEDS::UseCaseBuilder_wrap useCaseBuilder = theStudy->GetUseCaseBuilder();
294 bool isNewSO = false, isInUseCaseTree = false;
298 SO = aStudyBuilder->NewObject( theFatherObject );
301 else if ( !theFatherObject->FindSubObject( theTag, SO.inout() ))
303 SO = aStudyBuilder->NewObjectToTag( theFatherObject, theTag );
308 isInUseCaseTree = useCaseBuilder->IsUseCaseNode( SO );
313 isInUseCaseTree = useCaseBuilder->IsUseCaseNode( SO );
316 SALOMEDS::GenericAttribute_wrap anAttr;
317 if ( !CORBA::is_nil( theIOR ))
319 anAttr = aStudyBuilder->FindOrCreateAttribute( SO, "AttributeIOR" );
320 CORBA::String_var objStr = SMESH_Gen_i::GetORB()->object_to_string( theIOR );
321 SALOMEDS::AttributeIOR_wrap iorAttr = anAttr;
322 CORBA::String_var objStrCur = iorAttr->Value();
323 bool sameIOR = ( objStrCur.in() && strcmp( objStr.in(), objStrCur.in() ) == 0 );
326 iorAttr->SetValue( objStr.in() );
327 // UnRegister() !!! --> random problems when meshing in parallel (yacs foreach) in
328 // distributed python scripts, because simultaneously created meshes are
329 // published into the same SO; as a result the mesh published first dies
330 SALOME::GenericObj_var genObj = SALOME::GenericObj::_narrow( theIOR );
331 if ( !genObj->_is_nil() )
332 genObj->UnRegister();
337 anAttr = aStudyBuilder->FindOrCreateAttribute( SO, "AttributePixMap" );
338 SALOMEDS::AttributePixMap_wrap pm = anAttr;
339 pm->SetPixMap( thePixMap );
342 if ( !theSelectable ) {
343 anAttr = aStudyBuilder->FindOrCreateAttribute( SO, "AttributeSelectable" );
344 SALOMEDS::AttributeSelectable_wrap selAttr = anAttr;
345 selAttr->SetSelectable( false );
349 aStudyBuilder->RemoveReference( SO );// remove garbage reference (23336)
351 // add object to the use case tree
352 // (to support tree representation customization and drag-n-drop)
353 if ( isNewSO || !isInUseCaseTree )
355 // define the next tag after given one in the data tree to insert SObject
356 SALOMEDS::SObject_wrap curObj, objAfter;
357 if ( theFatherObject->GetLastChildTag() > theTag && theTag > 0 )
359 SALOMEDS::UseCaseIterator_wrap
360 anUseCaseIter = useCaseBuilder->GetUseCaseIterator(theFatherObject);
361 for ( ; anUseCaseIter->More(); anUseCaseIter->Next() ) {
362 curObj = anUseCaseIter->Value();
363 if ( curObj->Tag() > theTag ) {
369 if ( !CORBA::is_nil( objAfter ))
370 useCaseBuilder->InsertBefore( SO, objAfter ); // insert at given tag
371 else if ( !isInUseCaseTree )
372 useCaseBuilder->AppendTo( theFatherObject, SO ); // append to the end of list
377 //=======================================================================
380 //=======================================================================
382 void SMESH_Gen_i::SetName(SALOMEDS::SObject_ptr theSObject,
384 const char* theDefaultName)
386 if ( !theSObject->_is_nil() ) {
387 SALOMEDS::StudyBuilder_var aStudyBuilder = getStudyServant()->NewBuilder();
388 SALOMEDS::GenericAttribute_wrap anAttr =
389 aStudyBuilder->FindOrCreateAttribute( theSObject, "AttributeName" );
390 SALOMEDS::AttributeName_wrap aNameAttr = anAttr;
391 if ( theName && theName[0] ) {
392 std::string name( theName ); // trim trailing white spaces
393 for ( size_t i = name.size()-1; i > 0; --i )
394 if ( isspace( name[i] )) name[i] = '\0';
396 aNameAttr->SetValue( name.c_str() );
400 CORBA::String_var curName = aNameAttr->Value();
401 if ( strlen( curName.in() ) == 0 ) {
402 SMESH_Comment aName(theDefaultName);
403 aNameAttr->SetValue( ( aName<< "_" << theSObject->Tag()).c_str() );
409 //=======================================================================
410 //function : SetPixMap
412 //=======================================================================
414 void SMESH_Gen_i::SetPixMap(SALOMEDS::SObject_ptr theSObject,
415 const char* thePixMap)
417 if ( !theSObject->_is_nil() && thePixMap && thePixMap && thePixMap[0] )
419 SALOMEDS::StudyBuilder_var aStudyBuilder = getStudyServant()->NewBuilder();
420 SALOMEDS::GenericAttribute_wrap anAttr =
421 aStudyBuilder->FindOrCreateAttribute( theSObject, "AttributePixMap" );
422 SALOMEDS::AttributePixMap_wrap aPMAttr = anAttr;
423 aPMAttr->SetPixMap( thePixMap );
427 //=======================================================================
428 //function : addReference
430 //=======================================================================
432 void SMESH_Gen_i::addReference (SALOMEDS::SObject_ptr theSObject, CORBA::Object_ptr theToObject, int theTag)
434 SALOMEDS::Study_var aStudy = SMESH_Gen_i::getStudyServant();
435 SALOMEDS::SObject_wrap aToObjSO = SMESH_Gen_i::ObjectToSObject( theToObject );
436 if ( !aToObjSO->_is_nil() && !theSObject->_is_nil() ) {
437 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
438 SALOMEDS::SObject_wrap aReferenceSO;
440 // check if the reference to theToObject already exists
441 // and find a free label for the reference object
442 bool isReferred = false;
444 SALOMEDS::ChildIterator_wrap anIter = aStudy->NewChildIterator( theSObject );
445 for ( ; !isReferred && anIter->More(); anIter->Next(), ++tag ) {
446 SALOMEDS::SObject_wrap curSO = anIter->Value();
447 if ( curSO->ReferencedObject( aReferenceSO.inout() )) {
448 CORBA::String_var refEntry = aReferenceSO->GetID();
449 CORBA::String_var toEntry = aToObjSO->GetID();
450 if ( strcmp( refEntry, toEntry ) == 0 )
453 else if ( !theTag ) {
454 SALOMEDS::GenericAttribute_wrap anAttr;
455 if ( !curSO->FindAttribute( anAttr.inout(), "AttributeIOR" ))
464 if ( !theSObject->FindSubObject( theTag, aReferenceSO.inout() ))
465 aReferenceSO = aStudyBuilder->NewObjectToTag( theSObject, theTag );
467 aStudyBuilder->Addreference( aReferenceSO, aToObjSO );
469 // make the reference visible (invisible ref is created by createInvalidSubMesh())
470 aStudyBuilder->RemoveAttribute( aReferenceSO, "AttributeDrawable" );
472 // add reference to the use case tree
473 // (to support tree representation customization and drag-n-drop)
474 SALOMEDS::UseCaseBuilder_wrap useCaseBuilder = aStudy->GetUseCaseBuilder();
475 SALOMEDS::UseCaseIterator_wrap useCaseIter = useCaseBuilder->GetUseCaseIterator(theSObject);
476 for ( ; useCaseIter->More(); useCaseIter->Next() )
478 SALOMEDS::SObject_wrap curSO = useCaseIter->Value();
479 if ( curSO->Tag() == theTag )
482 useCaseBuilder->AppendTo( theSObject, aReferenceSO );
486 //=============================================================================
488 * SMESH_Gen_i::PublishInStudy
490 * Publish object in the study
492 //=============================================================================
494 SALOMEDS::SObject_ptr SMESH_Gen_i::PublishInStudy(SALOMEDS::SObject_ptr /*theSObject*/,
495 CORBA::Object_ptr theIOR,
498 Unexpect aCatch(SALOME_SalomeException);
499 SALOMEDS::SObject_wrap aSO;
500 if ( !myIsEnablePublish )
502 if ( CORBA::is_nil( theIOR ))
504 if(MYDEBUG) MESSAGE("PublishInStudy");
507 SMESH::SMESH_Mesh_var aMesh = SMESH::SMESH_Mesh::_narrow( theIOR );
508 if( !aMesh->_is_nil() )
509 aSO = PublishMesh( aMesh, theName );
511 // Publishing a sub-mesh
512 SMESH::SMESH_subMesh_var aSubMesh = SMESH::SMESH_subMesh::_narrow( theIOR );
513 if( aSO->_is_nil() && !aSubMesh->_is_nil() ) {
514 GEOM::GEOM_Object_var aShapeObject = aSubMesh->GetSubShape();
515 aMesh = aSubMesh->GetFather();
516 aSO = PublishSubMesh( aMesh, aSubMesh, aShapeObject, theName );
519 // Publishing a hypothesis or algorithm
520 SMESH::SMESH_Hypothesis_var aHyp = SMESH::SMESH_Hypothesis::_narrow( theIOR );
521 if ( aSO->_is_nil() && !aHyp->_is_nil() )
522 aSO = PublishHypothesis( aHyp, theName );
524 // Publishing a group
525 SMESH::SMESH_GroupBase_var aGroup = SMESH::SMESH_GroupBase::_narrow(theIOR);
526 if ( aSO->_is_nil() && !aGroup->_is_nil() ) {
527 GEOM::GEOM_Object_var aShapeObject;
528 aMesh = aGroup->GetMesh();
529 aSO = PublishGroup( aMesh, aGroup, aShapeObject, theName );
531 if(MYDEBUG) MESSAGE("PublishInStudy_END");
536 //=======================================================================
537 //function : PublishComponent
539 //=======================================================================
541 SALOMEDS::SComponent_ptr SMESH_Gen_i::PublishComponent()
543 if(MYDEBUG) MESSAGE("PublishComponent");
544 if ( !myIsEnablePublish )
545 return SALOMEDS::SComponent::_nil();
547 SALOMEDS::StudyBuilder_var aStudyBuilder = getStudyServant()->NewBuilder();
548 SALOMEDS::UseCaseBuilder_wrap useCaseBuilder = getStudyServant()->GetUseCaseBuilder();
550 std::string compDataType = ComponentDataType(); // SMESH module's data type
553 CORBA::String_var iorString = GetORB()->object_to_string( SMESH_Gen::_this() );
554 ior = std::string( iorString.in() ); // IOR of this SMESH engine
556 // Find study component which corresponds to this SMESH engine
558 SALOMEDS::SComponent_wrap father;
559 SALOMEDS::SComponentIterator_wrap citer = getStudyServant()->NewComponentIterator();
560 for ( ; citer->More(); citer->Next()) {
561 SALOMEDS::SComponent_wrap f_i = citer->Value();
562 CORBA::String_var ior_i;
563 bool ok = f_i->ComponentIOR(ior_i.out());
564 if ( ok && compDataType == f_i->ComponentDataType() && ior == ior_i.in()) {
570 if ( !CORBA::is_nil( father ) ) {
571 // check that the component is added to the use case browser
572 if ( !useCaseBuilder->IsUseCaseNode( father ) ) {
573 useCaseBuilder->SetRootCurrent();
574 useCaseBuilder->Append( father ); // component object is added as the top level item
576 return father._retn();
579 // If component for this SMESH engine does not exist in the study, create it
581 SALOME_ModuleCatalog::ModuleCatalog_var aCat = this->getModuleCatalog();
582 if ( CORBA::is_nil( aCat ) )
583 return father._retn();
585 SALOME_ModuleCatalog::Acomponent_var aComp = aCat->GetComponent( compDataType.c_str() );
586 if ( CORBA::is_nil( aComp ) )
587 return father._retn();
589 SALOMEDS::GenericAttribute_wrap anAttr;
590 SALOMEDS::AttributePixMap_wrap aPixmap;
592 father = aStudyBuilder->NewComponent( compDataType.c_str() );
593 aStudyBuilder->DefineComponentInstance( father, SMESH_Gen::_this() );
594 anAttr = aStudyBuilder->FindOrCreateAttribute( father, "AttributePixMap" );
596 aPixmap->SetPixMap( "ICON_OBJBROWSER_SMESH" );
597 CORBA::String_var userName = aComp->componentusername();
598 SetName( father, userName.in(), "MESH" );
599 // add component to the use case tree
600 // (to support tree representation customization and drag-n-drop)
601 useCaseBuilder->SetRootCurrent();
602 useCaseBuilder->Append( father ); // component object is added as the top level item
603 if(MYDEBUG) MESSAGE("PublishComponent--END");
605 return father._retn();
608 //=======================================================================
609 //function : PublishMesh
611 //=======================================================================
613 SALOMEDS::SObject_ptr SMESH_Gen_i::PublishMesh (SMESH::SMESH_Mesh_ptr theMesh,
616 if ( !myIsEnablePublish )
617 return SALOMEDS::SObject::_nil();
618 if ( CORBA::is_nil( theMesh ))
619 return SALOMEDS::SObject::_nil();
620 if(MYDEBUG) MESSAGE("PublishMesh--IN");
622 // find or publish a mesh
624 SALOMEDS::SObject_wrap aMeshSO = ObjectToSObject( theMesh );
625 if ( aMeshSO->_is_nil() )
627 SALOMEDS::SComponent_wrap father = PublishComponent();
628 if ( father->_is_nil() )
629 return aMeshSO._retn();
631 // Find correct free tag
632 long aTag = father->GetLastChildTag();
633 if ( aTag <= GetAlgorithmsRootTag() )
634 aTag = GetAlgorithmsRootTag() + 1;
638 aMeshSO = publish( theMesh, father, aTag, "ICON_SMESH_TREE_MESH_WARN" );
639 if ( aMeshSO->_is_nil() )
640 return aMeshSO._retn();
642 SetName( aMeshSO, theName, "Mesh" );
644 // Add shape reference
646 GEOM::GEOM_Object_var aShapeObject = theMesh->GetShapeToMesh();
647 if ( !CORBA::is_nil( aShapeObject )) {
648 addReference( aMeshSO, aShapeObject, GetRefOnShapeTag() );
650 // Publish global hypotheses
652 SMESH::ListOfHypothesis_var hypList = theMesh->GetHypothesisList( aShapeObject );
653 for ( CORBA::ULong i = 0; i < hypList->length(); i++ )
655 SMESH::SMESH_Hypothesis_var aHyp = SMESH::SMESH_Hypothesis::_narrow( hypList[ i ]);
656 SALOMEDS::SObject_wrap so = PublishHypothesis( aHyp );
657 AddHypothesisToShape( theMesh, aShapeObject, aHyp );
663 SMESH_Mesh_i* mesh_i = objectToServant<SMESH_Mesh_i>( theMesh );
665 return aMeshSO._retn();
666 map<int, SMESH_subMesh_i*>& subMap = mesh_i->_mapSubMesh_i;
667 map<int, SMESH_subMesh_i*>::iterator subIt = subMap.begin();
668 for ( ; subIt != subMap.end(); subIt++ ) {
669 SMESH::SMESH_subMesh_ptr aSubMesh = (*subIt).second->_this();
670 if ( !CORBA::is_nil( aSubMesh )) {
671 aShapeObject = aSubMesh->GetSubShape();
672 SALOMEDS::SObject_wrap( PublishSubMesh( theMesh, aSubMesh, aShapeObject ));
677 const map<int, SMESH::SMESH_GroupBase_ptr>& grMap = mesh_i->getGroups();
678 map<int, SMESH::SMESH_GroupBase_ptr>::const_iterator it = grMap.begin();
679 for ( ; it != grMap.end(); it++ )
681 SMESH::SMESH_GroupBase_ptr aGroup = (*it).second;
682 if ( !aGroup->_is_nil() ) {
683 GEOM::GEOM_Object_var aShapeObj;
684 SMESH::SMESH_GroupOnGeom_var aGeomGroup = SMESH::SMESH_GroupOnGeom::_narrow( aGroup );
685 if ( !aGeomGroup->_is_nil() )
686 aShapeObj = aGeomGroup->GetShape();
687 SALOMEDS::SObject_wrap( PublishGroup( theMesh, aGroup, aShapeObj ));
691 if(MYDEBUG) MESSAGE("PublishMesh_END");
692 return aMeshSO._retn();
695 //=======================================================================
696 //function : PublishSubMesh
698 //=======================================================================
700 SALOMEDS::SObject_ptr SMESH_Gen_i::PublishSubMesh (SMESH::SMESH_Mesh_ptr theMesh,
701 SMESH::SMESH_subMesh_ptr theSubMesh,
702 GEOM::GEOM_Object_ptr theShapeObject,
705 if ( !myIsEnablePublish )
706 return SALOMEDS::SObject::_nil();
707 if ( theMesh->_is_nil() || theSubMesh->_is_nil() || theShapeObject->_is_nil() )
708 return SALOMEDS::SObject::_nil();
710 std::string newName( theName ? theName : "" );
712 SALOMEDS::SObject_wrap aSubMeshSO = ObjectToSObject( theSubMesh );
713 if ( aSubMeshSO->_is_nil() )
715 SALOMEDS::SObject_wrap aMeshSO = ObjectToSObject( theMesh );
716 if ( aMeshSO->_is_nil() ) {
717 aMeshSO = PublishMesh( theMesh );
718 if ( aMeshSO->_is_nil())
719 return SALOMEDS::SObject::_nil();
721 // Find submesh sub-tree tag
723 const char* aRootName = "";
724 switch ( theShapeObject->GetShapeType() ) {
726 aRootTag = GetSubMeshOnVertexTag();
727 aRootName = "SubMeshes on Vertex";
730 aRootTag = GetSubMeshOnEdgeTag();
731 aRootName = "SubMeshes on Edge";
734 aRootTag = GetSubMeshOnWireTag();
735 aRootName = "SubMeshes on Wire";
738 aRootTag = GetSubMeshOnFaceTag();
739 aRootName = "SubMeshes on Face";
742 aRootTag = GetSubMeshOnShellTag();
743 aRootName = "SubMeshes on Shell";
746 aRootTag = GetSubMeshOnSolidTag();
747 aRootName = "SubMeshes on Solid";
750 aRootTag = GetSubMeshOnCompoundTag();
751 aRootName = "SubMeshes on Compound";
755 // Find or create submesh root
756 SALOMEDS::SObject_wrap aRootSO = publish ( CORBA::Object::_nil(),
757 aMeshSO, aRootTag, 0, false );
758 if ( aRootSO->_is_nil() )
759 return aSubMeshSO._retn();
761 SetName( aRootSO, aRootName );
763 // Add new sub-mesh to corresponding sub-tree
764 int tag = 0; // to use a new SObject
765 if ( theName && theName[0] == '0' )
767 // theName can be an entry of an invalid sub-mesh which theSubMesh should replace
768 SALOMEDS::SObject_wrap aSObj = getStudyServant()->FindObjectID( theName );
771 CORBA::String_var oldName = aSObj->GetName();
772 newName = oldName.in();
773 SALOMEDS::SObject_wrap aRootSO2 = aSObj->GetFather();
774 if ( aRootSO->Tag() == aRootSO2->Tag() ) // same parent
775 tag = aSObj->Tag(); // to use the same SObject
778 CORBA::Object_var anObj = SObjectToObject( aSObj );
779 SMESH::SMESH_subMesh_var sm = SMESH::SMESH_subMesh::_narrow( anObj );
780 theMesh->RemoveSubMesh( sm );
784 SMESH::array_of_ElementType_var elemTypes = theSubMesh->GetTypes();
785 const int isEmpty = ( elemTypes->length() == 0 );
786 const char* pm[2] = { "ICON_SMESH_TREE_MESH", "ICON_SMESH_TREE_MESH_WARN" };
787 aSubMeshSO = publish ( theSubMesh, aRootSO, tag, pm[isEmpty] );
788 if ( aSubMeshSO->_is_nil() )
789 return aSubMeshSO._retn();
791 highLightInvalid( aSubMeshSO, false ); // now it is valid
793 SetName( aSubMeshSO, newName.c_str(), "SubMesh" );
795 // Add reference to theShapeObject
797 addReference( aSubMeshSO, theShapeObject, GetRefOnShapeTag() );
799 // Publish hypothesis
801 SMESH::ListOfHypothesis_var hypList = theMesh->GetHypothesisList( theShapeObject );
802 for ( CORBA::ULong i = 0; i < hypList->length(); i++ )
804 SMESH::SMESH_Hypothesis_var aHyp = SMESH::SMESH_Hypothesis::_narrow( hypList[ i ]);
805 SALOMEDS::SObject_wrap so = PublishHypothesis( aHyp );
806 AddHypothesisToShape( theMesh, theShapeObject, aHyp );
809 return aSubMeshSO._retn();
812 //=======================================================================
813 //function : PublishGroup
815 //=======================================================================
817 SALOMEDS::SObject_ptr SMESH_Gen_i::PublishGroup (SMESH::SMESH_Mesh_ptr theMesh,
818 SMESH::SMESH_GroupBase_ptr theGroup,
819 GEOM::GEOM_Object_ptr theShapeObject,
822 if ( !myIsEnablePublish )
823 return SALOMEDS::SObject::_nil();
824 if (theMesh->_is_nil() || theGroup->_is_nil() )
825 return SALOMEDS::SObject::_nil();
827 SALOMEDS::SObject_wrap aGroupSO = ObjectToSObject( theGroup );
828 if ( aGroupSO->_is_nil() )
830 SALOMEDS::SObject_wrap aMeshSO = ObjectToSObject( theMesh );
831 if ( aMeshSO->_is_nil() ) {
832 aMeshSO = PublishInStudy( SALOMEDS::SObject::_nil(), theMesh, "");
833 if ( aMeshSO->_is_nil())
834 return SALOMEDS::SObject::_nil();
836 size_t aType = (int)theGroup->GetType();
837 const char* aRootNames[] = {
838 "Compound Groups", "Groups of Nodes", "Groups of Edges",
839 "Groups of Faces", "Groups of Volumes", "Groups of 0D Elements",
842 // Currently, groups with heterogeneous content are not supported
843 if ( aType != SMESH::ALL )
845 long aRootTag = GetNodeGroupsTag() + aType - 1;
847 // Find or create groups root
848 SALOMEDS::SObject_wrap aRootSO = publish ( CORBA::Object::_nil(),
849 aMeshSO, aRootTag, 0, false );
850 if ( aRootSO->_is_nil() ) return SALOMEDS::SObject::_nil();
852 if ( aType < sizeof(aRootNames)/sizeof(char*) )
853 SetName( aRootSO, aRootNames[aType] );
855 // Add new group to corresponding sub-tree
856 int isEmpty = ( theMesh->NbNodes() == 0 );
857 std::string pm[2] = { "ICON_SMESH_TREE_GROUP", "ICON_SMESH_TREE_MESH_WARN" };
860 if ( SMESH::DownCast< SMESH_GroupOnFilter_i* > ( theGroup )) // on filter
862 pm[0] = "ICON_SMESH_TREE_GROUP_ON_FILTER";
864 if ( theGroup->GetType() != SMESH::NODE )
867 SMESH::array_of_ElementType_var allElemTypes = theMesh->GetTypes();
868 for ( size_t i =0; i < allElemTypes->length() && isEmpty; ++i )
869 isEmpty = ( allElemTypes[i] != theGroup->GetType() );
872 else // standalone or on geometry
874 isEmpty = ( theGroup->Size() == 0 );
877 aGroupSO = publish ( theGroup, aRootSO, 0, pm[isEmpty].c_str() );
879 if ( aGroupSO->_is_nil() )
880 return aGroupSO._retn();
883 SetName( aGroupSO, theName, "Group" );
885 //Add reference to geometry
886 if ( !theShapeObject->_is_nil() )
887 addReference( aGroupSO, theShapeObject, GetRefOnShapeTag() );
889 return aGroupSO._retn();
892 //=======================================================================
893 //function : PublishHypothesis
895 //=======================================================================
897 SALOMEDS::SObject_ptr
898 SMESH_Gen_i::PublishHypothesis (SMESH::SMESH_Hypothesis_ptr theHyp,
901 if(MYDEBUG) MESSAGE("PublishHypothesis");
902 if ( !myIsEnablePublish )
903 return SALOMEDS::SObject::_nil();
904 if (theHyp->_is_nil())
905 return SALOMEDS::SObject::_nil();
907 CORBA::String_var hypType = theHyp->GetName();
909 SALOMEDS::SObject_wrap aHypSO = ObjectToSObject( theHyp );
910 if ( aHypSO->_is_nil() )
912 SALOMEDS::SComponent_wrap father = PublishComponent();
913 if ( father->_is_nil() )
914 return aHypSO._retn();
916 //Find or Create Hypothesis root
917 bool isAlgo = ( !SMESH::SMESH_Algo::_narrow( theHyp )->_is_nil() );
918 int aRootTag = isAlgo ? GetAlgorithmsRootTag() : GetHypothesisRootTag();
919 SALOMEDS::SObject_wrap aRootSO =
920 publish (CORBA::Object::_nil(),father, aRootTag,
921 isAlgo ? "ICON_SMESH_TREE_ALGO" : "ICON_SMESH_TREE_HYPO", false);
922 SetName( aRootSO, isAlgo ? "Algorithms" : "Hypotheses" );
924 // Add New Hypothesis
925 string aPmName = isAlgo ? "ICON_SMESH_TREE_ALGO_" : "ICON_SMESH_TREE_HYPO_";
926 aPmName += hypType.in();
927 // prepend plugin name to pixmap name
928 string pluginName = myHypCreatorMap[ hypType.in() ]->GetModuleName();
929 if ( pluginName != "StdMeshers" )
930 aPmName = pluginName + "::" + aPmName;
931 aHypSO = publish( theHyp, aRootSO, 0, aPmName.c_str() );
934 SetName( aHypSO, theName, hypType.in() );
936 if(MYDEBUG) MESSAGE("PublishHypothesis--END")
937 return aHypSO._retn();
940 //=======================================================================
941 //function : UpdateIcons
942 //purpose : update icons of a mesh and its children upon mesh modification
943 //=======================================================================
945 void SMESH_Gen_i::UpdateIcons( SMESH::SMESH_Mesh_ptr theMesh )
947 SMESH_Mesh_i* mesh_i = SMESH::DownCast< SMESH_Mesh_i* >( theMesh );
951 SALOMEDS::SObject_wrap so = ObjectToSObject( theMesh );
955 // set icon of the mesh
956 if ( mesh_i->NbNodes() == 0 )
957 SetPixMap( so, "ICON_SMESH_TREE_MESH_WARN" );
958 else if ( mesh_i->IsComputedOK() )
959 SetPixMap( so, "ICON_SMESH_TREE_MESH" );
960 else if ( mesh_i->HasShapeToMesh() )
961 SetPixMap( so, "ICON_SMESH_TREE_MESH_PARTIAL" );
963 SetPixMap( so, "ICON_SMESH_TREE_MESH_IMPORTED" );
965 // set icons of sub-objects
966 SALOMEDS::Study_var study = getStudyServant();
967 SALOMEDS::ChildIterator_wrap iter = study->NewChildIterator( so );
968 for ( ; iter->More(); iter->Next() )
970 so = iter->Value(); // 1st level child - root of algos, hyps, sub-meshes or groups
971 if ( so->Tag() < SMESH::Tag_FirstSubMesh )
974 SALOMEDS::ChildIterator_wrap subIter = study->NewChildIterator( so );
975 for ( ; subIter->More(); subIter->Next() )
977 so = subIter->Value(); // 2nd level child - a sub-mesh or group
979 CORBA::Object_var obj = SObjectToObject( so );
980 SMESH::SMESH_IDSource_var idSrc = SMESH::SMESH_IDSource::_narrow( obj );
981 if ( idSrc->_is_nil() )
984 SMESH::SMESH_GroupBase_var grp = SMESH::SMESH_GroupBase::_narrow( obj );
985 SMESH::SMESH_GroupOnFilter_var gof = SMESH::SMESH_GroupOnFilter::_narrow( obj );
986 const bool isGroup = !grp->_is_nil();
987 const bool isGroupOnFilter = !gof->_is_nil();
989 bool isEmpty = ( mesh_i->NbNodes() == 0 );
992 if ( isGroupOnFilter ) // GetTypes() can be very long on GroupOnFilter!
994 SMESH::smIdType_array_var nbByType = mesh_i->GetNbElementsByType();
995 isEmpty = ( nbByType[ grp->GetType() ] == 0 );
999 SMESH::array_of_ElementType_var elemTypes = idSrc->GetTypes();
1000 isEmpty = ( elemTypes->length() == 0 );
1004 // check if all sub-shapes of sub-mesh on group are computed
1005 // (pb: "Compute sub-mesh" menu is missing if a sub-mesh is partially computed)
1006 SMESH::SMESH_subMesh_var subMesh = SMESH::SMESH_subMesh::_narrow( obj );
1007 if ( !subMesh->_is_nil() )
1008 if ( SMESH_subMesh* sm = mesh_i->GetImpl().GetSubMeshContaining( subMesh->GetId() ))
1009 if ( sm->IsComputedPartially() )
1011 SetPixMap( so, "ICON_SMESH_TREE_MESH_PARTIAL" );
1019 SetPixMap( so, "ICON_SMESH_TREE_MESH_WARN");
1020 else if ( !isGroup )
1021 SetPixMap( so, "ICON_SMESH_TREE_MESH" );
1022 else if ( isGroupOnFilter )
1023 SetPixMap( so, "ICON_SMESH_TREE_GROUP_ON_FILTER" );
1025 SetPixMap( so, "ICON_SMESH_TREE_GROUP" );
1027 } // loop on sub-meshes or groups
1031 //=======================================================================
1032 //function : HighLightInvalid
1033 //purpose : change font color of a object in the Object Browser
1034 //=======================================================================
1036 void SMESH_Gen_i::HighLightInvalid( CORBA::Object_ptr theObject, bool isInvalid )
1038 SALOMEDS::SObject_wrap so = ObjectToSObject(theObject);
1039 highLightInvalid( so.in(), isInvalid );
1042 //=======================================================================
1043 //function : highLightInvalid
1044 //purpose : change font color of a object in the Object Browser
1045 //=======================================================================
1047 void SMESH_Gen_i::highLightInvalid( SALOMEDS::SObject_ptr theSObject, bool isInvalid )
1049 if ( !theSObject->_is_nil() )
1051 SALOMEDS::StudyBuilder_var studyBuilder = getStudyServant()->NewBuilder();
1054 SALOMEDS::Color red = { 178,34,34 }; // to differ from reference color
1055 SALOMEDS::GenericAttribute_wrap attr =
1056 studyBuilder->FindOrCreateAttribute( theSObject, "AttributeTextColor" );
1057 SALOMEDS::AttributeTextColor_wrap colorAttr = attr;
1058 colorAttr->SetTextColor( red );
1062 studyBuilder->RemoveAttribute( theSObject, "AttributeTextColor" );
1067 //=======================================================================
1068 //function : IsInvalid
1069 //purpose : Check object validity == absence of AttributeTextColor=(178,34,34)
1070 //=======================================================================
1072 bool SMESH_Gen_i::IsInvalid( SALOMEDS::SObject_ptr theSObject )
1074 bool isValid = true;
1075 if ( !theSObject->_is_nil() )
1077 SALOMEDS::GenericAttribute_wrap attr;
1078 SALOMEDS::StudyBuilder_var studyBuilder = getStudyServant()->NewBuilder();
1079 if ( studyBuilder->FindAttribute( theSObject, attr.inout(), "AttributeTextColor" ))
1081 SALOMEDS::AttributeTextColor_wrap colorAttr = attr;
1082 SALOMEDS::Color color = colorAttr->TextColor();
1083 isValid = ( color.R != 178 || color.G != 34 || color.B != 34 );
1089 //=======================================================================
1090 //function : GetMeshOrSubmeshByShape
1092 //=======================================================================
1094 SALOMEDS::SObject_ptr
1095 SMESH_Gen_i::GetMeshOrSubmeshByShape (SMESH::SMESH_Mesh_ptr theMesh,
1096 GEOM::GEOM_Object_ptr theShape)
1098 if(MYDEBUG) MESSAGE("GetMeshOrSubmeshByShape")
1099 SALOMEDS::SObject_wrap aMeshOrSubMesh;
1100 if (theMesh->_is_nil() || ( theShape->_is_nil() && theMesh->HasShapeToMesh()))
1101 return aMeshOrSubMesh._retn();
1103 TopoDS_Shape aShape;
1104 if(theMesh->HasShapeToMesh())
1105 aShape = GeomObjectToShape( theShape );
1107 aShape = SMESH_Mesh::PseudoShape();
1109 SMESH_Mesh_i* mesh_i = objectToServant<SMESH_Mesh_i>( theMesh );
1111 if ( !aShape.IsNull() && mesh_i && mesh_i->GetImpl().GetMeshDS() ) {
1112 SMESHDS_Mesh* meshDS = mesh_i->GetImpl().GetMeshDS();
1113 if ( aShape.IsSame( meshDS->ShapeToMesh() ))
1114 aMeshOrSubMesh = ObjectToSObject( theMesh );
1116 int shapeID = meshDS->ShapeToIndex( aShape );
1117 SMESH::SMESH_subMesh_var aSubMesh = mesh_i->getSubMesh(shapeID);
1118 if ( !aSubMesh->_is_nil() )
1119 aMeshOrSubMesh = ObjectToSObject( aSubMesh );
1122 if(MYDEBUG) MESSAGE("GetMeshOrSubmeshByShape--END")
1123 return aMeshOrSubMesh._retn();
1126 //=======================================================================
1127 //function : AddHypothesisToShape
1129 //=======================================================================
1131 bool SMESH_Gen_i::AddHypothesisToShape(SMESH::SMESH_Mesh_ptr theMesh,
1132 GEOM::GEOM_Object_ptr theShape,
1133 SMESH::SMESH_Hypothesis_ptr theHyp)
1135 if(MYDEBUG) MESSAGE("AddHypothesisToShape")
1136 if (theMesh->_is_nil() ||
1137 theHyp->_is_nil() || (theShape->_is_nil()
1138 && theMesh->HasShapeToMesh()) )
1141 SALOMEDS::SObject_wrap aMeshSO = ObjectToSObject( theMesh );
1142 if ( aMeshSO->_is_nil() )
1143 aMeshSO = PublishMesh( theMesh );
1144 SALOMEDS::SObject_wrap aHypSO = PublishHypothesis( theHyp );
1145 if ( aMeshSO->_is_nil() || aHypSO->_is_nil())
1148 // Find a mesh or submesh referring to theShape
1149 SALOMEDS::SObject_wrap aMeshOrSubMesh =
1150 GetMeshOrSubmeshByShape( theMesh, theShape );
1151 if ( aMeshOrSubMesh->_is_nil() )
1154 TopoDS_Shape aShape = GeomObjectToShape( theShape );
1155 SMESH_Mesh_i* mesh_i = objectToServant<SMESH_Mesh_i>( theMesh );
1156 if ( !aShape.IsNull() && mesh_i && mesh_i->GetImpl().GetMeshDS() ) {
1157 SMESHDS_Mesh* meshDS = mesh_i->GetImpl().GetMeshDS();
1158 int shapeID = meshDS->ShapeToIndex( aShape );
1159 SMESH::SMESH_subMesh_var aSubMesh = mesh_i->getSubMesh(shapeID);
1160 aMeshOrSubMesh = PublishSubMesh( theMesh, aSubMesh, theShape );
1162 if ( aMeshOrSubMesh->_is_nil() )
1166 //Find or Create Applied Hypothesis root
1167 bool aIsAlgo = !SMESH::SMESH_Algo::_narrow( theHyp )->_is_nil();
1168 SALOMEDS::SObject_wrap AHR =
1169 publish (CORBA::Object::_nil(), aMeshOrSubMesh,
1170 aIsAlgo ? GetRefOnAppliedAlgorithmsTag() : GetRefOnAppliedHypothesisTag(),
1171 aIsAlgo ? "ICON_SMESH_TREE_ALGO" : "ICON_SMESH_TREE_HYPO", false);
1172 SetName( AHR, aIsAlgo ? "Applied algorithms" : "Applied hypotheses" );
1174 addReference( AHR, theHyp );
1176 if(MYDEBUG) MESSAGE("AddHypothesisToShape--END")
1180 //=======================================================================
1181 //function : RemoveHypothesisFromShape
1183 //=======================================================================
1185 bool SMESH_Gen_i::RemoveHypothesisFromShape(SMESH::SMESH_Mesh_ptr theMesh,
1186 GEOM::GEOM_Object_ptr theShape,
1187 SMESH::SMESH_Hypothesis_ptr theHyp)
1189 if (theMesh->_is_nil() ||
1190 theHyp->_is_nil() || (theShape->_is_nil()
1191 && theMesh->HasShapeToMesh()))
1194 SALOMEDS::SObject_wrap aHypSO = ObjectToSObject( theHyp );
1195 if ( aHypSO->_is_nil() )
1198 CORBA::String_var hypEntry = aHypSO->GetID();
1200 // Find a mesh or sub-mesh referring to theShape
1201 SALOMEDS::SObject_wrap aMeshOrSubMesh =
1202 GetMeshOrSubmeshByShape( theMesh, theShape );
1203 if ( aMeshOrSubMesh->_is_nil() )
1206 // Find and remove a reference to aHypSO
1207 SALOMEDS::SObject_wrap aRef, anObj;
1208 SALOMEDS::ChildIterator_wrap it = getStudyServant()->NewChildIterator( aMeshOrSubMesh );
1210 for ( it->InitEx( true ); ( it->More() && !found ); it->Next() ) {
1211 anObj = it->Value();
1212 if (anObj->ReferencedObject( aRef.inout() ))
1214 CORBA::String_var refEntry = aRef->GetID();
1215 found = ( strcmp( refEntry, hypEntry ) == 0 );
1219 SALOMEDS::StudyBuilder_var builder = getStudyServant()->NewBuilder();
1220 builder->RemoveObject( anObj );
1227 //================================================================================
1229 * \brief Stores names of variables that WILL be passes as parameters when calling
1230 * some method of a given object.
1231 * \param [in] theObject - the object whose a method WILL be called with \a theParameters.
1232 * \param [in] theParameters - a string containing parameters separated by ':'.
1234 //================================================================================
1236 void SMESH_Gen_i::UpdateParameters(CORBA::Object_ptr theObject, const char* theParameters)
1238 // find variable names within theParameters
1241 myLastParameters.clear();
1242 myLastParamIndex.clear(); /* vector holding indices of virables within the string
1243 of all variables used for theObject */
1245 int pos = 0, prevPos = 0, len = strlen( theParameters );
1246 if ( len == 0 ) return;
1247 while ( pos <= len )
1249 if ( pos == len || theParameters[pos] == ':' )
1251 if ( prevPos < pos )
1253 string val( theParameters + prevPos, theParameters + pos );
1254 if ( !getStudyServant()->IsVariable( val.c_str() ))
1256 myLastParameters.push_back( val );
1257 nbVars += (! myLastParameters.back().empty() );
1261 myLastParameters.push_back("");
1272 // (1) variable names in the string of all variables used for theObject and
1273 // (2) indices of found variables in myLastParamIndex.
1275 // remember theObject
1276 SALOMEDS::SObject_wrap aSObj = ObjectToSObject(theObject);
1277 if ( aSObj->_is_nil() )
1279 CORBA::String_var anObjEntry = aSObj->GetID();
1280 myLastObj = anObjEntry.in();
1282 // get a string of variable names
1283 SALOMEDS::StudyBuilder_var aStudyBuilder = getStudyServant()->NewBuilder();
1284 SALOMEDS::GenericAttribute_wrap anAttr =
1285 aStudyBuilder->FindOrCreateAttribute( aSObj, "AttributeString" );
1286 SALOMEDS::AttributeString_wrap aStringAttr = anAttr;
1287 CORBA::String_var oldVars = aStringAttr->Value();
1288 std::string varStr = oldVars.in();
1290 // add new variables and find indices of variables
1291 for ( size_t i = 0; i < myLastParameters.size(); ++i )
1294 if ( !myLastParameters[i].empty() )
1296 // find index of myLastParameters[i] in varStr
1298 bool varFound = false;
1300 // varStr can be "A|B::C;*=2|D"
1301 const std::string separators(":|;*=");
1302 while ( pos < varStr.size() && !varFound )
1305 while ( separators.find( varStr[ pos ]) != std::string::npos )
1306 if ( ++pos >= varStr.size() )
1308 // skip repetition number following '='
1309 if ( varStr[ pos-1 ] == '=' )
1311 while ( '0' <= varStr[ pos ] && varStr[ pos ] <= '9' )
1313 continue; // to skip next separator
1315 // compare variable name
1316 if ( pos < varStr.size() )
1318 varFound = ( varStr.compare( pos, myLastParameters[i].size(), myLastParameters[i] ) == 0 &&
1319 // same string beginning but is length same?
1320 ( pos + myLastParameters[i].size() >= varStr.size() ||
1321 separators.find( varStr[ pos+1 ]) != std::string::npos ));
1323 varIndex = curIndex;
1325 pos = varStr.find_first_of( separators, pos ); // goto the next separator
1332 varStr += ":" + myLastParameters[i];
1333 varIndex = curIndex;
1336 myLastParamIndex.push_back( varIndex );
1338 aStringAttr->SetValue( varStr.c_str() );
1341 //================================================================================
1343 * \brief Return all variables used to create an object
1344 * \param [in] theObjectEntry - an object entry in the current study
1345 * \return std::vector< std::string > - all variable names (or values of removed variables)
1347 //================================================================================
1349 std::vector< std::string > SMESH_Gen_i::GetAllParameters(const std::string& theObjectEntry) const
1351 std::vector< std::string > varNames;
1353 SALOMEDS::SObject_wrap aSObj = getStudyServant()->FindObjectID( theObjectEntry.c_str() );
1355 // get a string of variable names
1356 SALOMEDS::StudyBuilder_var aStudyBuilder = getStudyServant()->NewBuilder();
1357 SALOMEDS::GenericAttribute_wrap anAttr =
1358 aStudyBuilder->FindOrCreateAttribute( aSObj, "AttributeString" );
1359 SALOMEDS::AttributeString_wrap aStringAttr = anAttr;
1360 CORBA::String_var oldVars = aStringAttr->Value();
1361 std::string varStr = oldVars.in();
1363 // separate variables within varStr;
1364 // varStr can be "A|B::C;*=2|D"
1366 const std::string separators(":|;*=");
1367 while ( pos < varStr.size() )
1370 pos = varStr.find_first_not_of( separators, pos );
1371 // while ( separators.find( varStr[ pos ]) != std::string::npos )
1372 // if ( ++pos >= varStr.size() )
1374 // skip repetition number following '='
1375 if ( varStr[ pos-1 ] == '=' )
1377 while ( '0' <= varStr[ pos ] && varStr[ pos ] <= '9' )
1379 continue; // to skip next separator
1381 // store variable name
1382 if ( pos < varStr.size() )
1384 size_t pos2 = varStr.find_first_of( separators, pos );
1385 varNames.push_back( varStr.substr( pos, pos2 - pos));
1392 //=======================================================================
1393 //function : ParseParameters
1394 //purpose : Replace variables by their values
1395 //=======================================================================
1396 // char* SMESH_Gen_i::ParseParameters(const char* theParameters)
1398 // //const char* aParameters = theParameters;
1399 // // const char* aParameters = CORBA::string_dup(theParameters);
1400 // TCollection_AsciiString anInputParams;
1401 // SALOMEDS::Study_var aStudy = getStudyServant();
1402 // if( !aStudy->_is_nil() ) {
1403 // // SALOMEDS::ListOfListOfStrings_var aSections = aStudy->ParseVariables(theParameters);
1404 // // for(int j=0;j<aSections->length();j++) {
1405 // // SALOMEDS::ListOfStrings aVars= aSections[j];
1406 // // for(int i=0;i<aVars.length();i++ ) {
1407 // // anInputParams += aStudy->IsVariable(aVars[i].in()) ?
1408 // // TCollection_AsciiString(aVars[i].in()) : TCollection_AsciiString("");
1409 // // if(i != aVars.length()-1)
1410 // // anInputParams+=":";
1412 // // if(j!=aSections->length()-1)
1413 // // anInputParams+="|";
1415 // TCollection_AsciiString paramStr( theParameters );
1416 // int beg = 0, end;
1417 // char sep, *pParams = (char*)paramStr.ToCString();
1418 // while ( beg < paramStr.Length() )
1421 // while ( ++end < paramStr.Length() )
1422 // if ( pParams[end] == ':' || pParams[end] == '|')
1424 // if ( end < paramStr.Length())
1426 // sep = pParams[end];
1427 // pParams[end] = '\0';
1429 // if ( aStudy->IsVariable( pParams+beg ))
1430 // anInputParams += pParams+beg;
1431 // if ( end < paramStr.Length() )
1432 // anInputParams += sep;
1438 // return CORBA::string_dup(anInputParams.ToCString());
1441 //=======================================================================
1442 //function : GetParameters
1444 //=======================================================================
1446 char* SMESH_Gen_i::GetParameters(CORBA::Object_ptr theObject)
1448 CORBA::String_var aResult("");
1450 SALOMEDS::SObject_wrap aSObj = ObjectToSObject( theObject );
1451 if ( !aSObj->_is_nil() )
1453 SALOMEDS::GenericAttribute_wrap attr;
1454 if ( aSObj->FindAttribute( attr.inout(), "AttributeString"))
1456 SALOMEDS::AttributeString_wrap strAttr = attr;
1457 aResult = strAttr->Value();
1460 return aResult._retn();
1463 //================================================================================
1465 * \brief Create a sub-mesh on a geometry that is not a sub-shape of the main shape
1466 * for the case where a valid sub-shape not found by CopyMeshWithGeom().
1467 * The invalid sub-mesh has GetId() < 0.
1469 //================================================================================
1471 SMESH::SMESH_subMesh_ptr
1472 SMESH_Gen_i::createInvalidSubMesh(SMESH::SMESH_Mesh_ptr theMesh,
1473 GEOM::GEOM_Object_ptr theStrangerGeom,
1474 const char* theName)
1476 SMESH::SMESH_subMesh_var subMesh;
1480 SMESH_Mesh_i* mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( theMesh );
1481 subMesh = mesh_i->createSubMesh( theStrangerGeom );
1483 if ( !subMesh->_is_nil() && CanPublishInStudy( subMesh ))
1485 SALOMEDS::SObject_wrap so = PublishSubMesh( theMesh, subMesh, theStrangerGeom, theName );
1487 // hide a reference to geometry
1488 if ( !so->_is_nil() )
1490 SALOMEDS::SObject_wrap refSO;
1491 if ( so->FindSubObject( GetRefOnShapeTag(), refSO.inout() ))
1493 SALOMEDS::StudyBuilder_var studyBuilder = getStudyServant()->NewBuilder();
1494 SALOMEDS::GenericAttribute_wrap attr =
1495 studyBuilder->FindOrCreateAttribute( refSO, "AttributeDrawable" );
1496 SALOMEDS::AttributeDrawable_wrap ga = attr;
1497 ga->SetDrawable( false );
1505 return subMesh._retn();
1513 //=======================================================================
1514 //function : addObject
1515 //purpose : register object in the internal map and return its id
1516 //=======================================================================
1518 int StudyContext::addObject( const std::string& theIOR )
1520 int nextId = getNextId();
1521 mapIdToIOR.Bind( nextId, theIOR );
1525 //=======================================================================
1527 //purpose : find the object id in the internal map by the IOR
1528 //=======================================================================
1530 int StudyContext::findId( const std::string& theIOR )
1532 TInt2StringMap::iterator imap;
1533 for ( imap = mapIdToIOR.begin(); imap != mapIdToIOR.end(); ++imap ) {
1534 if ( *imap == theIOR )
1535 return imap.Iterator().Key();
1540 //=======================================================================
1541 //function : getIORbyId
1542 //purpose : get object's IOR by id
1543 //=======================================================================
1545 std::string StudyContext::getIORbyId( const int theId )
1547 if ( mapIdToIOR.IsBound( theId ) )
1548 return mapIdToIOR( theId );
1549 return std::string();
1552 //=======================================================================
1553 //function : getIORbyOldId
1554 //purpose : get object's IOR by old id
1555 //=======================================================================
1557 std::string StudyContext::getIORbyOldId( const int theOldId )
1559 if ( mapIdToId.IsBound( theOldId ) )
1560 return getIORbyId( mapIdToId( theOldId ));
1561 return std::string();
1564 //=======================================================================
1565 //function : mapOldToNew
1566 //purpose : maps old object id to the new one (used when restoring data)
1567 //=======================================================================
1569 void StudyContext::mapOldToNew( const int oldId, const int newId )
1571 mapIdToId.Bind( oldId, newId );
1574 //=======================================================================
1575 //function : getOldId
1576 //purpose : get old id by a new one
1577 //=======================================================================
1579 int StudyContext::getOldId( const int newId )
1581 TInt2IntMap::iterator imap;
1582 for ( imap = mapIdToId.begin(); imap != mapIdToId.end(); ++imap ) {
1583 if ( *imap == newId )
1584 return imap.Iterator().Key();
1589 //=======================================================================
1591 //purpose : clear data
1592 //=======================================================================
1594 void StudyContext::Clear()