1 // Copyright (C) 2007-2020 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
551 std::string ior = SMESH_Gen_i::GetORB()->object_to_string( SMESH_Gen::_this() ); // IOR of this SMESH engine
553 // Find study component which corresponds to this SMESH engine
555 SALOMEDS::SComponent_wrap father;
556 SALOMEDS::SComponentIterator_wrap citer = getStudyServant()->NewComponentIterator();
557 for ( ; citer->More(); citer->Next()) {
558 SALOMEDS::SComponent_wrap f_i = citer->Value();
559 CORBA::String_var ior_i;
560 bool ok = f_i->ComponentIOR(ior_i.out());
561 if ( ok && compDataType == f_i->ComponentDataType() && ior == ior_i.in()) {
567 if ( !CORBA::is_nil( father ) ) {
568 // check that the component is added to the use case browser
569 if ( !useCaseBuilder->IsUseCaseNode( father ) ) {
570 useCaseBuilder->SetRootCurrent();
571 useCaseBuilder->Append( father ); // component object is added as the top level item
573 return father._retn();
576 // If component for this SMESH engine does not exist in the study, create it
578 SALOME_ModuleCatalog::ModuleCatalog_var aCat = this->getModuleCatalog();
579 if ( CORBA::is_nil( aCat ) )
580 return father._retn();
582 SALOME_ModuleCatalog::Acomponent_var aComp = aCat->GetComponent( compDataType.c_str() );
583 if ( CORBA::is_nil( aComp ) )
584 return father._retn();
586 SALOMEDS::GenericAttribute_wrap anAttr;
587 SALOMEDS::AttributePixMap_wrap aPixmap;
589 father = aStudyBuilder->NewComponent( compDataType.c_str() );
590 aStudyBuilder->DefineComponentInstance( father, SMESH_Gen::_this() );
591 anAttr = aStudyBuilder->FindOrCreateAttribute( father, "AttributePixMap" );
593 aPixmap->SetPixMap( "ICON_OBJBROWSER_SMESH" );
594 CORBA::String_var userName = aComp->componentusername();
595 SetName( father, userName.in(), "MESH" );
596 // add component to the use case tree
597 // (to support tree representation customization and drag-n-drop)
598 useCaseBuilder->SetRootCurrent();
599 useCaseBuilder->Append( father ); // component object is added as the top level item
600 if(MYDEBUG) MESSAGE("PublishComponent--END");
602 return father._retn();
605 //=======================================================================
606 //function : PublishMesh
608 //=======================================================================
610 SALOMEDS::SObject_ptr SMESH_Gen_i::PublishMesh (SMESH::SMESH_Mesh_ptr theMesh,
613 if ( !myIsEnablePublish )
614 return SALOMEDS::SObject::_nil();
615 if ( CORBA::is_nil( theMesh ))
616 return SALOMEDS::SObject::_nil();
617 if(MYDEBUG) MESSAGE("PublishMesh--IN");
619 // find or publish a mesh
621 SALOMEDS::SObject_wrap aMeshSO = ObjectToSObject( theMesh );
622 if ( aMeshSO->_is_nil() )
624 SALOMEDS::SComponent_wrap father = PublishComponent();
625 if ( father->_is_nil() )
626 return aMeshSO._retn();
628 // Find correct free tag
629 long aTag = father->GetLastChildTag();
630 if ( aTag <= GetAlgorithmsRootTag() )
631 aTag = GetAlgorithmsRootTag() + 1;
635 aMeshSO = publish( theMesh, father, aTag, "ICON_SMESH_TREE_MESH_WARN" );
636 if ( aMeshSO->_is_nil() )
637 return aMeshSO._retn();
639 SetName( aMeshSO, theName, "Mesh" );
641 // Add shape reference
643 GEOM::GEOM_Object_var aShapeObject = theMesh->GetShapeToMesh();
644 if ( !CORBA::is_nil( aShapeObject )) {
645 addReference( aMeshSO, aShapeObject, GetRefOnShapeTag() );
647 // Publish global hypotheses
649 SMESH::ListOfHypothesis_var hypList = theMesh->GetHypothesisList( aShapeObject );
650 for ( CORBA::ULong i = 0; i < hypList->length(); i++ )
652 SMESH::SMESH_Hypothesis_var aHyp = SMESH::SMESH_Hypothesis::_narrow( hypList[ i ]);
653 SALOMEDS::SObject_wrap so = PublishHypothesis( aHyp );
654 AddHypothesisToShape( theMesh, aShapeObject, aHyp );
660 SMESH_Mesh_i* mesh_i = objectToServant<SMESH_Mesh_i>( theMesh );
662 return aMeshSO._retn();
663 map<int, SMESH_subMesh_i*>& subMap = mesh_i->_mapSubMesh_i;
664 map<int, SMESH_subMesh_i*>::iterator subIt = subMap.begin();
665 for ( ; subIt != subMap.end(); subIt++ ) {
666 SMESH::SMESH_subMesh_ptr aSubMesh = (*subIt).second->_this();
667 if ( !CORBA::is_nil( aSubMesh )) {
668 aShapeObject = aSubMesh->GetSubShape();
669 SALOMEDS::SObject_wrap( PublishSubMesh( theMesh, aSubMesh, aShapeObject ));
674 const map<int, SMESH::SMESH_GroupBase_ptr>& grMap = mesh_i->getGroups();
675 map<int, SMESH::SMESH_GroupBase_ptr>::const_iterator it = grMap.begin();
676 for ( ; it != grMap.end(); it++ )
678 SMESH::SMESH_GroupBase_ptr aGroup = (*it).second;
679 if ( !aGroup->_is_nil() ) {
680 GEOM::GEOM_Object_var aShapeObj;
681 SMESH::SMESH_GroupOnGeom_var aGeomGroup = SMESH::SMESH_GroupOnGeom::_narrow( aGroup );
682 if ( !aGeomGroup->_is_nil() )
683 aShapeObj = aGeomGroup->GetShape();
684 SALOMEDS::SObject_wrap( PublishGroup( theMesh, aGroup, aShapeObj ));
688 if(MYDEBUG) MESSAGE("PublishMesh_END");
689 return aMeshSO._retn();
692 //=======================================================================
693 //function : PublishSubMesh
695 //=======================================================================
697 SALOMEDS::SObject_ptr SMESH_Gen_i::PublishSubMesh (SMESH::SMESH_Mesh_ptr theMesh,
698 SMESH::SMESH_subMesh_ptr theSubMesh,
699 GEOM::GEOM_Object_ptr theShapeObject,
702 if ( !myIsEnablePublish )
703 return SALOMEDS::SObject::_nil();
704 if ( theMesh->_is_nil() || theSubMesh->_is_nil() || theShapeObject->_is_nil() )
705 return SALOMEDS::SObject::_nil();
707 std::string newName( theName ? theName : "" );
709 SALOMEDS::SObject_wrap aSubMeshSO = ObjectToSObject( theSubMesh );
710 if ( aSubMeshSO->_is_nil() )
712 SALOMEDS::SObject_wrap aMeshSO = ObjectToSObject( theMesh );
713 if ( aMeshSO->_is_nil() ) {
714 aMeshSO = PublishMesh( theMesh );
715 if ( aMeshSO->_is_nil())
716 return SALOMEDS::SObject::_nil();
718 // Find submesh sub-tree tag
720 const char* aRootName = "";
721 switch ( theShapeObject->GetShapeType() ) {
723 aRootTag = GetSubMeshOnVertexTag();
724 aRootName = "SubMeshes on Vertex";
727 aRootTag = GetSubMeshOnEdgeTag();
728 aRootName = "SubMeshes on Edge";
731 aRootTag = GetSubMeshOnWireTag();
732 aRootName = "SubMeshes on Wire";
735 aRootTag = GetSubMeshOnFaceTag();
736 aRootName = "SubMeshes on Face";
739 aRootTag = GetSubMeshOnShellTag();
740 aRootName = "SubMeshes on Shell";
743 aRootTag = GetSubMeshOnSolidTag();
744 aRootName = "SubMeshes on Solid";
747 aRootTag = GetSubMeshOnCompoundTag();
748 aRootName = "SubMeshes on Compound";
752 // Find or create submesh root
753 SALOMEDS::SObject_wrap aRootSO = publish ( CORBA::Object::_nil(),
754 aMeshSO, aRootTag, 0, false );
755 if ( aRootSO->_is_nil() )
756 return aSubMeshSO._retn();
758 SetName( aRootSO, aRootName );
760 // Add new sub-mesh to corresponding sub-tree
761 int tag = 0; // to use a new SObject
762 if ( theName && theName[0] == '0' )
764 // theName can be an entry of an invalid sub-mesh which theSubMesh should replace
765 SALOMEDS::SObject_wrap aSObj = getStudyServant()->FindObjectID( theName );
768 CORBA::String_var oldName = aSObj->GetName();
769 newName = oldName.in();
770 SALOMEDS::SObject_wrap aRootSO2 = aSObj->GetFather();
771 if ( aRootSO->Tag() == aRootSO2->Tag() ) // same parent
772 tag = aSObj->Tag(); // to use the same SObject
775 CORBA::Object_var anObj = SObjectToObject( aSObj );
776 SMESH::SMESH_subMesh_var sm = SMESH::SMESH_subMesh::_narrow( anObj );
777 theMesh->RemoveSubMesh( sm );
781 SMESH::array_of_ElementType_var elemTypes = theSubMesh->GetTypes();
782 const int isEmpty = ( elemTypes->length() == 0 );
783 const char* pm[2] = { "ICON_SMESH_TREE_MESH", "ICON_SMESH_TREE_MESH_WARN" };
784 aSubMeshSO = publish ( theSubMesh, aRootSO, tag, pm[isEmpty] );
785 if ( aSubMeshSO->_is_nil() )
786 return aSubMeshSO._retn();
788 highLightInvalid( aSubMeshSO, false ); // now it is valid
790 SetName( aSubMeshSO, newName.c_str(), "SubMesh" );
792 // Add reference to theShapeObject
794 addReference( aSubMeshSO, theShapeObject, GetRefOnShapeTag() );
796 // Publish hypothesis
798 SMESH::ListOfHypothesis_var hypList = theMesh->GetHypothesisList( theShapeObject );
799 for ( CORBA::ULong i = 0; i < hypList->length(); i++ )
801 SMESH::SMESH_Hypothesis_var aHyp = SMESH::SMESH_Hypothesis::_narrow( hypList[ i ]);
802 SALOMEDS::SObject_wrap so = PublishHypothesis( aHyp );
803 AddHypothesisToShape( theMesh, theShapeObject, aHyp );
806 return aSubMeshSO._retn();
809 //=======================================================================
810 //function : PublishGroup
812 //=======================================================================
814 SALOMEDS::SObject_ptr SMESH_Gen_i::PublishGroup (SMESH::SMESH_Mesh_ptr theMesh,
815 SMESH::SMESH_GroupBase_ptr theGroup,
816 GEOM::GEOM_Object_ptr theShapeObject,
819 if ( !myIsEnablePublish )
820 return SALOMEDS::SObject::_nil();
821 if (theMesh->_is_nil() || theGroup->_is_nil() )
822 return SALOMEDS::SObject::_nil();
824 SALOMEDS::SObject_wrap aGroupSO = ObjectToSObject( theGroup );
825 if ( aGroupSO->_is_nil() )
827 SALOMEDS::SObject_wrap aMeshSO = ObjectToSObject( theMesh );
828 if ( aMeshSO->_is_nil() ) {
829 aMeshSO = PublishInStudy( SALOMEDS::SObject::_nil(), theMesh, "");
830 if ( aMeshSO->_is_nil())
831 return SALOMEDS::SObject::_nil();
833 size_t aType = (int)theGroup->GetType();
834 const char* aRootNames[] = {
835 "Compound Groups", "Groups of Nodes", "Groups of Edges",
836 "Groups of Faces", "Groups of Volumes", "Groups of 0D Elements",
839 // Currently, groups with heterogeneous content are not supported
840 if ( aType != SMESH::ALL )
842 long aRootTag = GetNodeGroupsTag() + aType - 1;
844 // Find or create groups root
845 SALOMEDS::SObject_wrap aRootSO = publish ( CORBA::Object::_nil(),
846 aMeshSO, aRootTag, 0, false );
847 if ( aRootSO->_is_nil() ) return SALOMEDS::SObject::_nil();
849 if ( aType < sizeof(aRootNames)/sizeof(char*) )
850 SetName( aRootSO, aRootNames[aType] );
852 // Add new group to corresponding sub-tree
853 int isEmpty = ( theMesh->NbNodes() == 0 );
854 std::string pm[2] = { "ICON_SMESH_TREE_GROUP", "ICON_SMESH_TREE_MESH_WARN" };
857 if ( SMESH::DownCast< SMESH_GroupOnFilter_i* > ( theGroup )) // on filter
859 pm[0] = "ICON_SMESH_TREE_GROUP_ON_FILTER";
861 if ( theGroup->GetType() != SMESH::NODE )
864 SMESH::array_of_ElementType_var allElemTypes = theMesh->GetTypes();
865 for ( size_t i =0; i < allElemTypes->length() && isEmpty; ++i )
866 isEmpty = ( allElemTypes[i] != theGroup->GetType() );
869 else // standalone or on geometry
871 isEmpty = ( theGroup->Size() == 0 );
874 aGroupSO = publish ( theGroup, aRootSO, 0, pm[isEmpty].c_str() );
876 if ( aGroupSO->_is_nil() )
877 return aGroupSO._retn();
880 SetName( aGroupSO, theName, "Group" );
882 //Add reference to geometry
883 if ( !theShapeObject->_is_nil() )
884 addReference( aGroupSO, theShapeObject, GetRefOnShapeTag() );
886 return aGroupSO._retn();
889 //=======================================================================
890 //function : PublishHypothesis
892 //=======================================================================
894 SALOMEDS::SObject_ptr
895 SMESH_Gen_i::PublishHypothesis (SMESH::SMESH_Hypothesis_ptr theHyp,
898 if(MYDEBUG) MESSAGE("PublishHypothesis");
899 if ( !myIsEnablePublish )
900 return SALOMEDS::SObject::_nil();
901 if (theHyp->_is_nil())
902 return SALOMEDS::SObject::_nil();
904 CORBA::String_var hypType = theHyp->GetName();
906 SALOMEDS::SObject_wrap aHypSO = ObjectToSObject( theHyp );
907 if ( aHypSO->_is_nil() )
909 SALOMEDS::SComponent_wrap father = PublishComponent();
910 if ( father->_is_nil() )
911 return aHypSO._retn();
913 //Find or Create Hypothesis root
914 bool isAlgo = ( !SMESH::SMESH_Algo::_narrow( theHyp )->_is_nil() );
915 int aRootTag = isAlgo ? GetAlgorithmsRootTag() : GetHypothesisRootTag();
916 SALOMEDS::SObject_wrap aRootSO =
917 publish (CORBA::Object::_nil(),father, aRootTag,
918 isAlgo ? "ICON_SMESH_TREE_ALGO" : "ICON_SMESH_TREE_HYPO", false);
919 SetName( aRootSO, isAlgo ? "Algorithms" : "Hypotheses" );
921 // Add New Hypothesis
922 string aPmName = isAlgo ? "ICON_SMESH_TREE_ALGO_" : "ICON_SMESH_TREE_HYPO_";
923 aPmName += hypType.in();
924 // prepend plugin name to pixmap name
925 string pluginName = myHypCreatorMap[ hypType.in() ]->GetModuleName();
926 if ( pluginName != "StdMeshers" )
927 aPmName = pluginName + "::" + aPmName;
928 aHypSO = publish( theHyp, aRootSO, 0, aPmName.c_str() );
931 SetName( aHypSO, theName, hypType.in() );
933 if(MYDEBUG) MESSAGE("PublishHypothesis--END")
934 return aHypSO._retn();
937 //=======================================================================
938 //function : UpdateIcons
939 //purpose : update icons of a mesh and its children upon mesh modification
940 //=======================================================================
942 void SMESH_Gen_i::UpdateIcons( SMESH::SMESH_Mesh_ptr theMesh )
944 SMESH_Mesh_i* mesh_i = SMESH::DownCast< SMESH_Mesh_i* >( theMesh );
948 SALOMEDS::SObject_wrap so = ObjectToSObject( theMesh );
952 // set icon of the mesh
953 if ( mesh_i->NbNodes() == 0 )
954 SetPixMap( so, "ICON_SMESH_TREE_MESH_WARN" );
955 else if ( mesh_i->IsComputedOK() )
956 SetPixMap( so, "ICON_SMESH_TREE_MESH" );
957 else if ( mesh_i->HasShapeToMesh() )
958 SetPixMap( so, "ICON_SMESH_TREE_MESH_PARTIAL" );
960 SetPixMap( so, "ICON_SMESH_TREE_MESH_IMPORTED" );
962 // set icons of sub-objects
963 SALOMEDS::Study_var study = getStudyServant();
964 SALOMEDS::ChildIterator_wrap iter = study->NewChildIterator( so );
965 for ( ; iter->More(); iter->Next() )
967 so = iter->Value(); // 1st level child - root of algos, hyps, sub-meshes or groups
968 if ( so->Tag() < SMESH::Tag_FirstSubMesh )
971 SALOMEDS::ChildIterator_wrap subIter = study->NewChildIterator( so );
972 for ( ; subIter->More(); subIter->Next() )
974 so = subIter->Value(); // 2nd level child - a sub-mesh or group
976 CORBA::Object_var obj = SObjectToObject( so );
977 SMESH::SMESH_IDSource_var idSrc = SMESH::SMESH_IDSource::_narrow( obj );
978 if ( idSrc->_is_nil() )
981 SMESH::SMESH_GroupBase_var grp = SMESH::SMESH_GroupBase::_narrow( obj );
982 SMESH::SMESH_GroupOnFilter_var gof = SMESH::SMESH_GroupOnFilter::_narrow( obj );
983 const bool isGroup = !grp->_is_nil();
984 const bool isGroupOnFilter = !gof->_is_nil();
986 bool isEmpty = ( mesh_i->NbNodes() == 0 );
989 if ( isGroupOnFilter ) // GetTypes() can be very long on GroupOnFilter!
991 SMESH::long_array_var nbByType = mesh_i->GetNbElementsByType();
992 isEmpty = ( nbByType[ grp->GetType() ] == 0 );
996 SMESH::array_of_ElementType_var elemTypes = idSrc->GetTypes();
997 isEmpty = ( elemTypes->length() == 0 );
1001 // check if all sub-shapes of sub-mesh on group are computed
1002 // (pb: "Compute sub-mesh" menu is missing if a sub-mesh is partially computed)
1003 SMESH::SMESH_subMesh_var subMesh = SMESH::SMESH_subMesh::_narrow( obj );
1004 if ( !subMesh->_is_nil() )
1005 if ( SMESH_subMesh* sm = mesh_i->GetImpl().GetSubMeshContaining( subMesh->GetId() ))
1006 if ( sm->IsComputedPartially() )
1008 SetPixMap( so, "ICON_SMESH_TREE_MESH_PARTIAL" );
1016 SetPixMap( so, "ICON_SMESH_TREE_MESH_WARN");
1017 else if ( !isGroup )
1018 SetPixMap( so, "ICON_SMESH_TREE_MESH" );
1019 else if ( isGroupOnFilter )
1020 SetPixMap( so, "ICON_SMESH_TREE_GROUP_ON_FILTER" );
1022 SetPixMap( so, "ICON_SMESH_TREE_GROUP" );
1024 } // loop on sub-meshes or groups
1028 //=======================================================================
1029 //function : HighLightInvalid
1030 //purpose : change font color of a object in the Object Browser
1031 //=======================================================================
1033 void SMESH_Gen_i::HighLightInvalid( CORBA::Object_ptr theObject, bool isInvalid )
1035 SALOMEDS::SObject_wrap so = ObjectToSObject(theObject);
1036 highLightInvalid( so.in(), isInvalid );
1039 //=======================================================================
1040 //function : highLightInvalid
1041 //purpose : change font color of a object in the Object Browser
1042 //=======================================================================
1044 void SMESH_Gen_i::highLightInvalid( SALOMEDS::SObject_ptr theSObject, bool isInvalid )
1046 if ( !theSObject->_is_nil() )
1048 SALOMEDS::StudyBuilder_var studyBuilder = getStudyServant()->NewBuilder();
1051 SALOMEDS::Color red = { 178,34,34 }; // to differ from reference color
1052 SALOMEDS::GenericAttribute_wrap attr =
1053 studyBuilder->FindOrCreateAttribute( theSObject, "AttributeTextColor" );
1054 SALOMEDS::AttributeTextColor_wrap colorAttr = attr;
1055 colorAttr->SetTextColor( red );
1059 studyBuilder->RemoveAttribute( theSObject, "AttributeTextColor" );
1064 //=======================================================================
1065 //function : IsInvalid
1066 //purpose : Check object validity == absence of AttributeTextColor=(178,34,34)
1067 //=======================================================================
1069 bool SMESH_Gen_i::IsInvalid( SALOMEDS::SObject_ptr theSObject )
1071 bool isValid = true;
1072 if ( !theSObject->_is_nil() )
1074 SALOMEDS::GenericAttribute_wrap attr;
1075 SALOMEDS::StudyBuilder_var studyBuilder = getStudyServant()->NewBuilder();
1076 if ( studyBuilder->FindAttribute( theSObject, attr.inout(), "AttributeTextColor" ))
1078 SALOMEDS::AttributeTextColor_wrap colorAttr = attr;
1079 SALOMEDS::Color color = colorAttr->TextColor();
1080 isValid = ( color.R != 178 || color.G != 34 || color.B != 34 );
1086 //=======================================================================
1087 //function : GetMeshOrSubmeshByShape
1089 //=======================================================================
1091 SALOMEDS::SObject_ptr
1092 SMESH_Gen_i::GetMeshOrSubmeshByShape (SMESH::SMESH_Mesh_ptr theMesh,
1093 GEOM::GEOM_Object_ptr theShape)
1095 if(MYDEBUG) MESSAGE("GetMeshOrSubmeshByShape")
1096 SALOMEDS::SObject_wrap aMeshOrSubMesh;
1097 if (theMesh->_is_nil() || ( theShape->_is_nil() && theMesh->HasShapeToMesh()))
1098 return aMeshOrSubMesh._retn();
1100 TopoDS_Shape aShape;
1101 if(theMesh->HasShapeToMesh())
1102 aShape = GeomObjectToShape( theShape );
1104 aShape = SMESH_Mesh::PseudoShape();
1106 SMESH_Mesh_i* mesh_i = objectToServant<SMESH_Mesh_i>( theMesh );
1108 if ( !aShape.IsNull() && mesh_i && mesh_i->GetImpl().GetMeshDS() ) {
1109 SMESHDS_Mesh* meshDS = mesh_i->GetImpl().GetMeshDS();
1110 if ( aShape.IsSame( meshDS->ShapeToMesh() ))
1111 aMeshOrSubMesh = ObjectToSObject( theMesh );
1113 int shapeID = meshDS->ShapeToIndex( aShape );
1114 SMESH::SMESH_subMesh_var aSubMesh = mesh_i->getSubMesh(shapeID);
1115 if ( !aSubMesh->_is_nil() )
1116 aMeshOrSubMesh = ObjectToSObject( aSubMesh );
1119 if(MYDEBUG) MESSAGE("GetMeshOrSubmeshByShape--END")
1120 return aMeshOrSubMesh._retn();
1123 //=======================================================================
1124 //function : AddHypothesisToShape
1126 //=======================================================================
1128 bool SMESH_Gen_i::AddHypothesisToShape(SMESH::SMESH_Mesh_ptr theMesh,
1129 GEOM::GEOM_Object_ptr theShape,
1130 SMESH::SMESH_Hypothesis_ptr theHyp)
1132 if(MYDEBUG) MESSAGE("AddHypothesisToShape")
1133 if (theMesh->_is_nil() ||
1134 theHyp->_is_nil() || (theShape->_is_nil()
1135 && theMesh->HasShapeToMesh()) )
1138 SALOMEDS::SObject_wrap aMeshSO = ObjectToSObject( theMesh );
1139 if ( aMeshSO->_is_nil() )
1140 aMeshSO = PublishMesh( theMesh );
1141 SALOMEDS::SObject_wrap aHypSO = PublishHypothesis( theHyp );
1142 if ( aMeshSO->_is_nil() || aHypSO->_is_nil())
1145 // Find a mesh or submesh referring to theShape
1146 SALOMEDS::SObject_wrap aMeshOrSubMesh =
1147 GetMeshOrSubmeshByShape( theMesh, theShape );
1148 if ( aMeshOrSubMesh->_is_nil() )
1151 TopoDS_Shape aShape = GeomObjectToShape( theShape );
1152 SMESH_Mesh_i* mesh_i = objectToServant<SMESH_Mesh_i>( theMesh );
1153 if ( !aShape.IsNull() && mesh_i && mesh_i->GetImpl().GetMeshDS() ) {
1154 SMESHDS_Mesh* meshDS = mesh_i->GetImpl().GetMeshDS();
1155 int shapeID = meshDS->ShapeToIndex( aShape );
1156 SMESH::SMESH_subMesh_var aSubMesh = mesh_i->getSubMesh(shapeID);
1157 aMeshOrSubMesh = PublishSubMesh( theMesh, aSubMesh, theShape );
1159 if ( aMeshOrSubMesh->_is_nil() )
1163 //Find or Create Applied Hypothesis root
1164 bool aIsAlgo = !SMESH::SMESH_Algo::_narrow( theHyp )->_is_nil();
1165 SALOMEDS::SObject_wrap AHR =
1166 publish (CORBA::Object::_nil(), aMeshOrSubMesh,
1167 aIsAlgo ? GetRefOnAppliedAlgorithmsTag() : GetRefOnAppliedHypothesisTag(),
1168 aIsAlgo ? "ICON_SMESH_TREE_ALGO" : "ICON_SMESH_TREE_HYPO", false);
1169 SetName( AHR, aIsAlgo ? "Applied algorithms" : "Applied hypotheses" );
1171 addReference( AHR, theHyp );
1173 if(MYDEBUG) MESSAGE("AddHypothesisToShape--END")
1177 //=======================================================================
1178 //function : RemoveHypothesisFromShape
1180 //=======================================================================
1182 bool SMESH_Gen_i::RemoveHypothesisFromShape(SMESH::SMESH_Mesh_ptr theMesh,
1183 GEOM::GEOM_Object_ptr theShape,
1184 SMESH::SMESH_Hypothesis_ptr theHyp)
1186 if (theMesh->_is_nil() ||
1187 theHyp->_is_nil() || (theShape->_is_nil()
1188 && theMesh->HasShapeToMesh()))
1191 SALOMEDS::SObject_wrap aHypSO = ObjectToSObject( theHyp );
1192 if ( aHypSO->_is_nil() )
1195 CORBA::String_var hypEntry = aHypSO->GetID();
1197 // Find a mesh or sub-mesh referring to theShape
1198 SALOMEDS::SObject_wrap aMeshOrSubMesh =
1199 GetMeshOrSubmeshByShape( theMesh, theShape );
1200 if ( aMeshOrSubMesh->_is_nil() )
1203 // Find and remove a reference to aHypSO
1204 SALOMEDS::SObject_wrap aRef, anObj;
1205 SALOMEDS::ChildIterator_wrap it = getStudyServant()->NewChildIterator( aMeshOrSubMesh );
1207 for ( it->InitEx( true ); ( it->More() && !found ); it->Next() ) {
1208 anObj = it->Value();
1209 if (anObj->ReferencedObject( aRef.inout() ))
1211 CORBA::String_var refEntry = aRef->GetID();
1212 found = ( strcmp( refEntry, hypEntry ) == 0 );
1216 SALOMEDS::StudyBuilder_var builder = getStudyServant()->NewBuilder();
1217 builder->RemoveObject( anObj );
1224 //================================================================================
1226 * \brief Stores names of variables that WILL be passes as parameters when calling
1227 * some method of a given object.
1228 * \param [in] theObject - the object whose a method WILL be called with \a theParameters.
1229 * \param [in] theParameters - a string containing parameters separated by ':'.
1231 //================================================================================
1233 void SMESH_Gen_i::UpdateParameters(CORBA::Object_ptr theObject, const char* theParameters)
1235 // find variable names within theParameters
1238 myLastParameters.clear();
1239 myLastParamIndex.clear(); /* vector holding indices of virables within the string
1240 of all variables used for theObject */
1242 int pos = 0, prevPos = 0, len = strlen( theParameters );
1243 if ( len == 0 ) return;
1244 while ( pos <= len )
1246 if ( pos == len || theParameters[pos] == ':' )
1248 if ( prevPos < pos )
1250 string val( theParameters + prevPos, theParameters + pos );
1251 if ( !getStudyServant()->IsVariable( val.c_str() ))
1253 myLastParameters.push_back( val );
1254 nbVars += (! myLastParameters.back().empty() );
1258 myLastParameters.push_back("");
1269 // (1) variable names in the string of all variables used for theObject and
1270 // (2) indices of found variables in myLastParamIndex.
1272 // remember theObject
1273 SALOMEDS::SObject_wrap aSObj = ObjectToSObject(theObject);
1274 if ( aSObj->_is_nil() )
1276 CORBA::String_var anObjEntry = aSObj->GetID();
1277 myLastObj = anObjEntry.in();
1279 // get a string of variable names
1280 SALOMEDS::StudyBuilder_var aStudyBuilder = getStudyServant()->NewBuilder();
1281 SALOMEDS::GenericAttribute_wrap anAttr =
1282 aStudyBuilder->FindOrCreateAttribute( aSObj, "AttributeString" );
1283 SALOMEDS::AttributeString_wrap aStringAttr = anAttr;
1284 CORBA::String_var oldVars = aStringAttr->Value();
1285 std::string varStr = oldVars.in();
1287 // add new variables and find indices of variables
1288 for ( size_t i = 0; i < myLastParameters.size(); ++i )
1291 if ( !myLastParameters[i].empty() )
1293 // find index of myLastParameters[i] in varStr
1295 bool varFound = false;
1297 // varStr can be "A|B::C;*=2|D"
1298 const std::string separators(":|;*=");
1299 while ( pos < varStr.size() && !varFound )
1302 while ( separators.find( varStr[ pos ]) != std::string::npos )
1303 if ( ++pos >= varStr.size() )
1305 // skip repetition number following '='
1306 if ( varStr[ pos-1 ] == '=' )
1308 while ( '0' <= varStr[ pos ] && varStr[ pos ] <= '9' )
1310 continue; // to skip next separator
1312 // compare variable name
1313 if ( pos < varStr.size() )
1315 varFound = ( varStr.compare( pos, myLastParameters[i].size(), myLastParameters[i] ) == 0 &&
1316 // same string beginning but is length same?
1317 ( pos + myLastParameters[i].size() >= varStr.size() ||
1318 separators.find( varStr[ pos+1 ]) != std::string::npos ));
1320 varIndex = curIndex;
1322 pos = varStr.find_first_of( separators, pos ); // goto the next separator
1329 varStr += ":" + myLastParameters[i];
1330 varIndex = curIndex;
1333 myLastParamIndex.push_back( varIndex );
1335 aStringAttr->SetValue( varStr.c_str() );
1338 //================================================================================
1340 * \brief Return all variables used to create an object
1341 * \param [in] theObjectEntry - an object entry in the current study
1342 * \return std::vector< std::string > - all variable names (or values of removed variables)
1344 //================================================================================
1346 std::vector< std::string > SMESH_Gen_i::GetAllParameters(const std::string& theObjectEntry) const
1348 std::vector< std::string > varNames;
1350 SALOMEDS::SObject_wrap aSObj = getStudyServant()->FindObjectID( theObjectEntry.c_str() );
1352 // get a string of variable names
1353 SALOMEDS::StudyBuilder_var aStudyBuilder = getStudyServant()->NewBuilder();
1354 SALOMEDS::GenericAttribute_wrap anAttr =
1355 aStudyBuilder->FindOrCreateAttribute( aSObj, "AttributeString" );
1356 SALOMEDS::AttributeString_wrap aStringAttr = anAttr;
1357 CORBA::String_var oldVars = aStringAttr->Value();
1358 std::string varStr = oldVars.in();
1360 // separate variables within varStr;
1361 // varStr can be "A|B::C;*=2|D"
1363 const std::string separators(":|;*=");
1364 while ( pos < varStr.size() )
1367 pos = varStr.find_first_not_of( separators, pos );
1368 // while ( separators.find( varStr[ pos ]) != std::string::npos )
1369 // if ( ++pos >= varStr.size() )
1371 // skip repetition number following '='
1372 if ( varStr[ pos-1 ] == '=' )
1374 while ( '0' <= varStr[ pos ] && varStr[ pos ] <= '9' )
1376 continue; // to skip next separator
1378 // store variable name
1379 if ( pos < varStr.size() )
1381 size_t pos2 = varStr.find_first_of( separators, pos );
1382 varNames.push_back( varStr.substr( pos, pos2 - pos));
1389 //=======================================================================
1390 //function : ParseParameters
1391 //purpose : Replace variables by their values
1392 //=======================================================================
1393 // char* SMESH_Gen_i::ParseParameters(const char* theParameters)
1395 // //const char* aParameters = theParameters;
1396 // // const char* aParameters = CORBA::string_dup(theParameters);
1397 // TCollection_AsciiString anInputParams;
1398 // SALOMEDS::Study_var aStudy = getStudyServant();
1399 // if( !aStudy->_is_nil() ) {
1400 // // SALOMEDS::ListOfListOfStrings_var aSections = aStudy->ParseVariables(theParameters);
1401 // // for(int j=0;j<aSections->length();j++) {
1402 // // SALOMEDS::ListOfStrings aVars= aSections[j];
1403 // // for(int i=0;i<aVars.length();i++ ) {
1404 // // anInputParams += aStudy->IsVariable(aVars[i].in()) ?
1405 // // TCollection_AsciiString(aVars[i].in()) : TCollection_AsciiString("");
1406 // // if(i != aVars.length()-1)
1407 // // anInputParams+=":";
1409 // // if(j!=aSections->length()-1)
1410 // // anInputParams+="|";
1412 // TCollection_AsciiString paramStr( theParameters );
1413 // int beg = 0, end;
1414 // char sep, *pParams = (char*)paramStr.ToCString();
1415 // while ( beg < paramStr.Length() )
1418 // while ( ++end < paramStr.Length() )
1419 // if ( pParams[end] == ':' || pParams[end] == '|')
1421 // if ( end < paramStr.Length())
1423 // sep = pParams[end];
1424 // pParams[end] = '\0';
1426 // if ( aStudy->IsVariable( pParams+beg ))
1427 // anInputParams += pParams+beg;
1428 // if ( end < paramStr.Length() )
1429 // anInputParams += sep;
1435 // return CORBA::string_dup(anInputParams.ToCString());
1438 //=======================================================================
1439 //function : GetParameters
1441 //=======================================================================
1443 char* SMESH_Gen_i::GetParameters(CORBA::Object_ptr theObject)
1445 CORBA::String_var aResult("");
1447 SALOMEDS::SObject_wrap aSObj = ObjectToSObject( theObject );
1448 if ( !aSObj->_is_nil() )
1450 SALOMEDS::GenericAttribute_wrap attr;
1451 if ( aSObj->FindAttribute( attr.inout(), "AttributeString"))
1453 SALOMEDS::AttributeString_wrap strAttr = attr;
1454 aResult = strAttr->Value();
1457 return aResult._retn();
1460 //================================================================================
1462 * \brief Create a sub-mesh on a geometry that is not a sub-shape of the main shape
1463 * for the case where a valid sub-shape not found by CopyMeshWithGeom().
1464 * The invalid sub-mesh has GetId() < 0.
1466 //================================================================================
1468 SMESH::SMESH_subMesh_ptr
1469 SMESH_Gen_i::createInvalidSubMesh(SMESH::SMESH_Mesh_ptr theMesh,
1470 GEOM::GEOM_Object_ptr theStrangerGeom,
1471 const char* theName)
1473 SMESH::SMESH_subMesh_var subMesh;
1477 SMESH_Mesh_i* mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( theMesh );
1478 subMesh = mesh_i->createSubMesh( theStrangerGeom );
1480 if ( !subMesh->_is_nil() && CanPublishInStudy( subMesh ))
1482 SALOMEDS::SObject_wrap so = PublishSubMesh( theMesh, subMesh, theStrangerGeom, theName );
1484 // hide a reference to geometry
1485 if ( !so->_is_nil() )
1487 SALOMEDS::SObject_wrap refSO;
1488 if ( so->FindSubObject( GetRefOnShapeTag(), refSO.inout() ))
1490 SALOMEDS::StudyBuilder_var studyBuilder = getStudyServant()->NewBuilder();
1491 SALOMEDS::GenericAttribute_wrap attr =
1492 studyBuilder->FindOrCreateAttribute( refSO, "AttributeDrawable" );
1493 SALOMEDS::AttributeDrawable_wrap ga = attr;
1494 ga->SetDrawable( false );
1502 return subMesh._retn();
1510 //=======================================================================
1511 //function : addObject
1512 //purpose : register object in the internal map and return its id
1513 //=======================================================================
1515 int StudyContext::addObject( const std::string& theIOR )
1517 int nextId = getNextId();
1518 mapIdToIOR.Bind( nextId, theIOR );
1522 //=======================================================================
1524 //purpose : find the object id in the internal map by the IOR
1525 //=======================================================================
1527 int StudyContext::findId( const std::string& theIOR )
1529 TInt2StringMap::iterator imap;
1530 for ( imap = mapIdToIOR.begin(); imap != mapIdToIOR.end(); ++imap ) {
1531 if ( *imap == theIOR )
1532 return imap.Iterator().Key();
1537 //=======================================================================
1538 //function : getIORbyId
1539 //purpose : get object's IOR by id
1540 //=======================================================================
1542 std::string StudyContext::getIORbyId( const int theId )
1544 if ( mapIdToIOR.IsBound( theId ) )
1545 return mapIdToIOR( theId );
1546 return std::string();
1549 //=======================================================================
1550 //function : getIORbyOldId
1551 //purpose : get object's IOR by old id
1552 //=======================================================================
1554 std::string StudyContext::getIORbyOldId( const int theOldId )
1556 if ( mapIdToId.IsBound( theOldId ) )
1557 return getIORbyId( mapIdToId( theOldId ));
1558 return std::string();
1561 //=======================================================================
1562 //function : mapOldToNew
1563 //purpose : maps old object id to the new one (used when restoring data)
1564 //=======================================================================
1566 void StudyContext::mapOldToNew( const int oldId, const int newId )
1568 mapIdToId.Bind( oldId, newId );
1571 //=======================================================================
1572 //function : getOldId
1573 //purpose : get old id by a new one
1574 //=======================================================================
1576 int StudyContext::getOldId( const int newId )
1578 TInt2IntMap::iterator imap;
1579 for ( imap = mapIdToId.begin(); imap != mapIdToId.end(); ++imap ) {
1580 if ( *imap == newId )
1581 return imap.Iterator().Key();
1586 //=======================================================================
1588 //purpose : clear data
1589 //=======================================================================
1591 void StudyContext::Clear()