Salome HOME
NPAL16716. Compound: To create the groups of initial meshes. V4_1_1 V4_1_1rc2
authorvtn <vtn@opencascade.com>
Thu, 21 Feb 2008 12:52:25 +0000 (12:52 +0000)
committervtn <vtn@opencascade.com>
Thu, 21 Feb 2008 12:52:25 +0000 (12:52 +0000)
doc/salome/gui/SMESH/images/buildcompound.png
doc/salome/gui/SMESH/input/building_compounds.doc
idl/SMESH_Gen.idl
src/SMESHGUI/SMESHGUI_BuildCompoundDlg.cxx
src/SMESHGUI/SMESHGUI_BuildCompoundDlg.h
src/SMESH_I/SMESH_2smeshpy.cxx
src/SMESH_I/SMESH_Gen_i.cxx
src/SMESH_I/SMESH_Gen_i.hxx

index 79a6073..1a5bea1 100755 (executable)
Binary files a/doc/salome/gui/SMESH/images/buildcompound.png and b/doc/salome/gui/SMESH/images/buildcompound.png differ
index 5905565..d42f388 100644 (file)
@@ -34,6 +34,12 @@ become the elements of Group1 on the Compound_Mesh, or</li>
 becomes Group1_2. See \ref grouping_elements_page "Creating Groups"
 for more information about groups.</li>
 </ul>
 becomes Group1_2. See \ref grouping_elements_page "Creating Groups"
 for more information about groups.</li>
 </ul>
+<li><b>Create common groups for initial meshes</b> checkbox permits to
+automatically create groups of all elements of the same type
+(nodes, edges, faces and volumes) for the resulting mesh from the
+elements
+of the initial meshes.
+</li>
 <li>You can simply unite meshes or choose to <b>Merge coincident nodes
 and elements</b>, in which case it is possible to define the \b Tolerance
 for this operation.</li>
 <li>You can simply unite meshes or choose to <b>Merge coincident nodes
 and elements</b>, in which case it is possible to define the \b Tolerance
 for this operation.</li>
@@ -43,4 +49,4 @@ for this operation.</li>
 
 \image html image160.gif
 
 
 \image html image160.gif
 
-*/
\ No newline at end of file
+*/
index 96083e1..362bea4 100644 (file)
@@ -276,6 +276,20 @@ module SMESH
       raises ( SALOME::SALOME_Exception );
 
     /*!
       raises ( SALOME::SALOME_Exception );
 
     /*!
+     * Concatenate the given meshes into one mesh.
+     * Union groups with the same name and type if
+     * theUniteIdenticalGroups flag is true.
+     * Merge coincident nodes and elements if 
+     * theMergeNodesAndElements flag is true.
+     * Create the groups of all elements from initial meshes.
+     */
+    SMESH_Mesh ConcatenateWithGroups(in mesh_array theMeshesArray, 
+                                    in boolean    theUniteIdenticalGroups, 
+                                     in boolean    theMergeNodesAndElements, 
+                                     in double     theMergeTolerance)
+      raises ( SALOME::SALOME_Exception );
+
+    /*!
      * \brief Return id of object, registered in current study context
      *
      * Can be used to check if the object was created in the same container, as this engine.
      * \brief Return id of object, registered in current study context
      *
      * Can be used to check if the object was created in the same container, as this engine.
index 781959a..95e918f 100644 (file)
@@ -150,17 +150,21 @@ SMESHGUI_BuildCompoundDlg::SMESHGUI_BuildCompoundDlg( SMESHGUI* theModule)
   ComboBoxUnion = new QComboBox(GroupArgs, "ComboBoxUnion");
   GroupArgsLayout->addMultiCellWidget(ComboBoxUnion, 1, 1, 3, 3);
 
   ComboBoxUnion = new QComboBox(GroupArgs, "ComboBoxUnion");
   GroupArgsLayout->addMultiCellWidget(ComboBoxUnion, 1, 1, 3, 3);
 
+  CheckBoxCommon = new QCheckBox(GroupArgs, "CheckBoxCommon");
+  CheckBoxCommon->setText(tr("CREATE_COMMON_GROUPS" ));
+  GroupArgsLayout->addMultiCellWidget(CheckBoxCommon, 2, 2, 0, 3);
+
   CheckBoxMerge = new QCheckBox(GroupArgs, "CheckBoxMerge");
   CheckBoxMerge->setText(tr("MERGE_NODES_AND_ELEMENTS" ));
   CheckBoxMerge = new QCheckBox(GroupArgs, "CheckBoxMerge");
   CheckBoxMerge->setText(tr("MERGE_NODES_AND_ELEMENTS" ));
-  GroupArgsLayout->addMultiCellWidget(CheckBoxMerge, 2, 2, 0, 3);
+  GroupArgsLayout->addMultiCellWidget(CheckBoxMerge, 3, 3, 0, 3);
 
   TextLabelTol = new QLabel (GroupArgs, "TextLabelTol");
   TextLabelTol->setText(tr("SMESH_TOLERANCE"));
   TextLabelTol->setAlignment(Qt::AlignCenter);
 
   TextLabelTol = new QLabel (GroupArgs, "TextLabelTol");
   TextLabelTol->setText(tr("SMESH_TOLERANCE"));
   TextLabelTol->setAlignment(Qt::AlignCenter);
-  GroupArgsLayout->addMultiCellWidget(TextLabelTol, 3, 3, 0, 1);
+  GroupArgsLayout->addMultiCellWidget(TextLabelTol, 4, 4, 0, 1);
   SpinBoxTol = new SMESHGUI_SpinBox (GroupArgs, "SpinBoxTol");
   SpinBoxTol->RangeStepAndValidator(0.0, COORD_MAX, 0.1, 6);
   SpinBoxTol = new SMESHGUI_SpinBox (GroupArgs, "SpinBoxTol");
   SpinBoxTol->RangeStepAndValidator(0.0, COORD_MAX, 0.1, 6);
-  GroupArgsLayout->addMultiCellWidget(SpinBoxTol, 3, 3, 2, 3);
+  GroupArgsLayout->addMultiCellWidget(SpinBoxTol, 4, 4, 2, 3);
 
   SMESHGUI_BuildCompoundDlgLayout->addWidget(GroupArgs, 2, 0);
 
 
   SMESHGUI_BuildCompoundDlgLayout->addWidget(GroupArgs, 2, 0);
 
@@ -313,12 +317,18 @@ bool SMESHGUI_BuildCompoundDlg::ClickOnApply()
       
       SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
       // concatenate meshes
       
       SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
       // concatenate meshes
-      SMESH::SMESH_Mesh_var aCompoundMesh = 
-       aSMESHGen->Concatenate(myMeshArray, 
-                              !(ComboBoxUnion->currentItem()), 
-                              CheckBoxMerge->isChecked(), 
-                              SpinBoxTol->GetValue());
-      
+      SMESH::SMESH_Mesh_var aCompoundMesh;
+      if(CheckBoxCommon->isChecked())
+       aCompoundMesh = aSMESHGen->ConcatenateWithGroups(myMeshArray, 
+                                                        !(ComboBoxUnion->currentItem()), 
+                                                        CheckBoxMerge->isChecked(), 
+                                                        SpinBoxTol->GetValue());
+      else
+       aCompoundMesh = aSMESHGen->Concatenate(myMeshArray, 
+                                              !(ComboBoxUnion->currentItem()), 
+                                              CheckBoxMerge->isChecked(), 
+                                              SpinBoxTol->GetValue());
+     
       SMESH::SetName( SMESH::FindSObject( aCompoundMesh ), LineEditName->text().latin1() );
       QApplication::restoreOverrideCursor();
       mySMESHGUI->updateObjBrowser();
       SMESH::SetName( SMESH::FindSObject( aCompoundMesh ), LineEditName->text().latin1() );
       QApplication::restoreOverrideCursor();
       mySMESHGUI->updateObjBrowser();
index c7bc29c..a3f1c77 100644 (file)
@@ -108,6 +108,7 @@ public :
   QLineEdit* LineEditMeshes;
   QLabel* TextLabelUnion;
   QComboBox* ComboBoxUnion;
   QLineEdit* LineEditMeshes;
   QLabel* TextLabelUnion;
   QComboBox* ComboBoxUnion;
+  QCheckBox* CheckBoxCommon;
   QCheckBox* CheckBoxMerge;
   QLabel* TextLabelTol;
   SMESHGUI_SpinBox* SpinBoxTol;
   QCheckBox* CheckBoxMerge;
   QLabel* TextLabelTol;
   SMESHGUI_SpinBox* SpinBoxTol;
index f933abf..c9d70e0 100644 (file)
@@ -338,7 +338,8 @@ void _pyGen::Process( const Handle(_pyCommand)& theCommand )
   }
 
   // Concatenate( [mesh1, ...], ... )
   }
 
   // Concatenate( [mesh1, ...], ... )
-  if ( theCommand->GetMethod() == "Concatenate" )
+  if ( theCommand->GetMethod() == "Concatenate" ||
+       theCommand->GetMethod() == "ConcatenateWithGroups")
   {
     AddMeshAccessorMethod( theCommand );
   }
   {
     AddMeshAccessorMethod( theCommand );
   }
index 4b0f697..f4139ed 100644 (file)
@@ -1419,6 +1419,52 @@ SMESH::SMESH_Mesh_ptr SMESH_Gen_i::Concatenate(const SMESH::mesh_array& theMeshe
                                               CORBA::Double            theMergeTolerance)
   throw ( SALOME::SALOME_Exception )
 {
                                               CORBA::Double            theMergeTolerance)
   throw ( SALOME::SALOME_Exception )
 {
+  return ConcatenateCommon(theMeshesArray,
+                          theUniteIdenticalGroups,
+                          theMergeNodesAndElements,
+                          theMergeTolerance,
+                          false);
+}
+
+//================================================================================
+/*!
+ *  SMESH_Gen_i::ConcatenateWithGroups
+ *
+ *  Concatenate the given meshes into one mesh
+ *  Create the groups of all elements from initial meshes
+ */
+//================================================================================
+
+SMESH::SMESH_Mesh_ptr
+SMESH_Gen_i::ConcatenateWithGroups(const SMESH::mesh_array& theMeshesArray,
+                                  CORBA::Boolean           theUniteIdenticalGroups, 
+                                   CORBA::Boolean           theMergeNodesAndElements, 
+                                   CORBA::Double            theMergeTolerance)
+  throw ( SALOME::SALOME_Exception )
+{
+  return ConcatenateCommon(theMeshesArray,
+                           theUniteIdenticalGroups,
+                           theMergeNodesAndElements,
+                           theMergeTolerance,
+                          true);
+}
+
+//================================================================================
+/*!
+ *  SMESH_Gen_i::ConcatenateCommon
+ *
+ *  Concatenate the given meshes into one mesh
+ */
+//================================================================================
+
+SMESH::SMESH_Mesh_ptr
+SMESH_Gen_i::ConcatenateCommon(const SMESH::mesh_array& theMeshesArray,
+                              CORBA::Boolean           theUniteIdenticalGroups, 
+                               CORBA::Boolean           theMergeNodesAndElements, 
+                               CORBA::Double            theMergeTolerance,
+                              CORBA::Boolean           theCommonGroups)
+  throw ( SALOME::SALOME_Exception )
+{
   typedef map<int, int> TIDsMap;
   typedef list<SMESH::SMESH_Group_var> TListOfNewGroups;
   typedef map< pair<string, SMESH::ElementType>, TListOfNewGroups > TGroupsMap;
   typedef map<int, int> TIDsMap;
   typedef list<SMESH::SMESH_Group_var> TListOfNewGroups;
   typedef map< pair<string, SMESH::ElementType>, TListOfNewGroups > TGroupsMap;
@@ -1458,6 +1504,23 @@ SMESH::SMESH_Mesh_ptr SMESH_Gen_i::Concatenate(const SMESH::mesh_array& theMeshe
            const SMDS_MeshElement* aNewElem = 0;
            int anElemNbNodes = 0;
 
            const SMDS_MeshElement* aNewElem = 0;
            int anElemNbNodes = 0;
 
+           int anNbNodes   = 0;
+           int anNbEdges   = 0;
+           int anNbFaces   = 0;
+           int anNbVolumes = 0;
+
+           SMESH::long_array_var anIDsNodes   = new SMESH::long_array();
+           SMESH::long_array_var anIDsEdges   = new SMESH::long_array();
+           SMESH::long_array_var anIDsFaces   = new SMESH::long_array();
+           SMESH::long_array_var anIDsVolumes = new SMESH::long_array();
+
+           if( theCommonGroups ) {
+             anIDsNodes->length(   anInitMeshDS->NbNodes()   );
+             anIDsEdges->length(   anInitMeshDS->NbEdges()   );
+             anIDsFaces->length(   anInitMeshDS->NbFaces()   );
+             anIDsVolumes->length( anInitMeshDS->NbVolumes() );
+           }
+
            for ( int j = 0; itElems->more(); j++) {
              anElem = itElems->next();
              SMDSAbs_ElementType anElemType = anElem->GetType();
            for ( int j = 0; itElems->more(); j++) {
              anElem = itElems->next();
              SMDSAbs_ElementType anElemType = anElem->GetType();
@@ -1474,6 +1537,8 @@ SMESH::SMESH_Mesh_ptr SMESH_Gen_i::Concatenate(const SMESH::mesh_array& theMeshe
                if ( nodesMap.find(aNode->GetID()) == nodesMap.end() ) {
                  aNewNode = aNewMeshDS->AddNode(aNode->X(), aNode->Y(), aNode->Z());
                  nodesMap.insert( make_pair(aNode->GetID(), aNewNode->GetID()) );
                if ( nodesMap.find(aNode->GetID()) == nodesMap.end() ) {
                  aNewNode = aNewMeshDS->AddNode(aNode->X(), aNode->Y(), aNode->Z());
                  nodesMap.insert( make_pair(aNode->GetID(), aNewNode->GetID()) );
+                 if( theCommonGroups )
+                   anIDsNodes[anNbNodes++] = aNewNode->GetID();
                }
                else
                  aNewNode = aNewMeshDS->FindNode( nodesMap.find(aNode->GetID())->second );
                }
                else
                  aNewNode = aNewMeshDS->FindNode( nodesMap.find(aNode->GetID())->second );
@@ -1489,6 +1554,8 @@ SMESH::SMESH_Mesh_ptr SMESH_Gen_i::Concatenate(const SMESH::mesh_array& theMeshe
                    aNewElem = aNewMeshDS->AddPolyhedralVolume(aNodesArray, 
                                                               aVolume->GetQuanities());
                    elemsMap.insert(make_pair(anElem->GetID(), aNewElem->GetID()));
                    aNewElem = aNewMeshDS->AddPolyhedralVolume(aNodesArray, 
                                                               aVolume->GetQuanities());
                    elemsMap.insert(make_pair(anElem->GetID(), aNewElem->GetID()));
+                   if( theCommonGroups )
+                     anIDsVolumes[anNbVolumes++] = aNewElem->GetID();
                  }
                }
              else {
                  }
                }
              else {
@@ -1497,6 +1564,14 @@ SMESH::SMESH_Mesh_ptr SMESH_Gen_i::Concatenate(const SMESH::mesh_array& theMeshe
                                                 anElemType,
                                                 anElem->IsPoly());
                elemsMap.insert(make_pair(anElem->GetID(), aNewElem->GetID()));
                                                 anElemType,
                                                 anElem->IsPoly());
                elemsMap.insert(make_pair(anElem->GetID(), aNewElem->GetID()));
+               if( theCommonGroups ) {
+                 if( anElemType == SMDSAbs_Edge )
+                   anIDsEdges[anNbEdges++] = aNewElem->GetID();
+                 else if( anElemType == SMDSAbs_Face )
+                   anIDsFaces[anNbFaces++] = aNewElem->GetID();
+                 else if( anElemType == SMDSAbs_Volume )
+                   anIDsVolumes[anNbVolumes++] = aNewElem->GetID();
+               }
              } 
            }//elems loop
            
              } 
            }//elems loop
            
@@ -1507,12 +1582,81 @@ SMESH::SMESH_Mesh_ptr SMESH_Gen_i::Concatenate(const SMESH::mesh_array& theMeshe
            SMESH::long_array_var anInitIDs = new SMESH::long_array();
            SMESH::long_array_var anNewIDs = new SMESH::long_array();
            SMESH::SMESH_Group_var aNewGroup;
            SMESH::long_array_var anInitIDs = new SMESH::long_array();
            SMESH::long_array_var anNewIDs = new SMESH::long_array();
            SMESH::SMESH_Group_var aNewGroup;
+
+           SMESH::ElementType aGroupType;
+           CORBA::String_var aGroupName;
+           if ( theCommonGroups ) {
+             for(aGroupType=SMESH::NODE;aGroupType<=SMESH::VOLUME;aGroupType=(SMESH::ElementType)(aGroupType+1)) {
+               string str = "Gr";
+               SALOMEDS::SObject_var aMeshSObj = ObjectToSObject( myCurrentStudy, anInitMesh );
+               if(aMeshSObj)
+                 str += aMeshSObj->GetName();
+               str += "_";
+
+               int anLen = 0;
+
+               switch(aGroupType) {
+               case SMESH::NODE:
+                 str += "Nodes";
+                 anIDsNodes->length(anNbNodes);
+                 anLen = anNbNodes;
+                 break;
+               case SMESH::EDGE:
+                 str += "Edges";
+                 anIDsEdges->length(anNbEdges);
+                 anLen = anNbEdges;
+                 break;
+               case SMESH::FACE:
+                 str += "Faces";
+                 anIDsFaces->length(anNbFaces);
+                 anLen = anNbFaces;
+                 break;
+               case SMESH::VOLUME:
+                 str += "Volumes";
+                 anIDsVolumes->length(anNbVolumes);
+                 anLen = anNbVolumes;
+                 break;
+               default:
+                 break;
+               }
+
+               if(anLen) {
+                 aGroupName = str.c_str();
+
+                 // add a new group in the mesh
+                 aNewGroup = aNewImpl->CreateGroup(aGroupType, aGroupName);
+
+                 switch(aGroupType) {
+                 case SMESH::NODE:
+                   aNewGroup->Add( anIDsNodes );
+                   break;
+                 case SMESH::EDGE:
+                   aNewGroup->Add( anIDsEdges );
+                   break;
+                 case SMESH::FACE:
+                   aNewGroup->Add( anIDsFaces );
+                   break;
+                 case SMESH::VOLUME:
+                   aNewGroup->Add( anIDsVolumes );
+                   break;
+                 default:
+                   break;
+                 }
+               
+                 aListOfNewGroups.clear();
+                 aListOfNewGroups.push_back(aNewGroup);
+                 aGroupsMap.insert(make_pair( make_pair(aGroupName, aGroupType), aListOfNewGroups ));
+               }
+             }
+           }
+
+           // check that current group name and type don't have identical ones in union mesh
            for (int i = 0; i < aListOfGroups->length(); i++) {
              aGroup = aListOfGroups[i];
              aListOfNewGroups.clear();
            for (int i = 0; i < aListOfGroups->length(); i++) {
              aGroup = aListOfGroups[i];
              aListOfNewGroups.clear();
-             SMESH::ElementType aGroupType = aGroup->GetType();
-             CORBA::String_var aGroupName = aGroup->GetName();
-             
+             aGroupType = aGroup->GetType();
+             aGroupName = aGroup->GetName();
+
              TGroupsMap::iterator anIter = aGroupsMap.find(make_pair(aGroupName, aGroupType));
 
              // convert a list of IDs
              TGroupsMap::iterator anIter = aGroupsMap.find(make_pair(aGroupName, aGroupType));
 
              // convert a list of IDs
@@ -1579,7 +1723,11 @@ SMESH::SMESH_Mesh_ptr SMESH_Gen_i::Concatenate(const SMESH::mesh_array& theMeshe
   }
   
   // Update Python script
   }
   
   // Update Python script
-  aPythonDump << aNewMesh << " = " << this << ".Concatenate(";
+  aPythonDump << aNewMesh << " = " << this;
+  if( !theCommonGroups )
+    aPythonDump << ".Concatenate(";
+  else
+    aPythonDump << ".ConcatenateWithGroups(";
   aPythonDump << "[";
   for ( int i = 0; i < theMeshesArray.length(); i++) {
     if (i > 0) aPythonDump << ", ";
   aPythonDump << "[";
   for ( int i = 0; i < theMeshesArray.length(); i++) {
     if (i > 0) aPythonDump << ", ";
@@ -1587,7 +1735,7 @@ SMESH::SMESH_Mesh_ptr SMESH_Gen_i::Concatenate(const SMESH::mesh_array& theMeshe
   }
   aPythonDump << "], ";
   aPythonDump << theUniteIdenticalGroups << ", "
   }
   aPythonDump << "], ";
   aPythonDump << theUniteIdenticalGroups << ", "
-              << theMergeNodesAndElements << ", "
+             << theMergeNodesAndElements << ", "
               << theMergeTolerance << ")";
 
   return aNewMesh._retn();
               << theMergeTolerance << ")";
 
   return aNewMesh._retn();
index d97b6fb..f8d43bb 100644 (file)
@@ -260,12 +260,27 @@ public:
     throw ( SALOME::SALOME_Exception );
 
   // Concatenate the given meshes into one mesh
     throw ( SALOME::SALOME_Exception );
 
   // Concatenate the given meshes into one mesh
+  SMESH::SMESH_Mesh_ptr ConcatenateCommon(const SMESH::mesh_array& theMeshesArray, 
+                                         CORBA::Boolean           theUniteIdenticalGroups, 
+                                         CORBA::Boolean           theMergeNodesAndElements, 
+                                         CORBA::Double            theMergeTolerance,
+                                         CORBA::Boolean           theCommonGroups)
+    throw ( SALOME::SALOME_Exception );
+
+  // Concatenate the given meshes into one mesh
   SMESH::SMESH_Mesh_ptr Concatenate(const SMESH::mesh_array& theMeshesArray, 
                                    CORBA::Boolean           theUniteIdenticalGroups, 
                                    CORBA::Boolean           theMergeNodesAndElements, 
                                    CORBA::Double            theMergeTolerance)
     throw ( SALOME::SALOME_Exception );
 
   SMESH::SMESH_Mesh_ptr Concatenate(const SMESH::mesh_array& theMeshesArray, 
                                    CORBA::Boolean           theUniteIdenticalGroups, 
                                    CORBA::Boolean           theMergeNodesAndElements, 
                                    CORBA::Double            theMergeTolerance)
     throw ( SALOME::SALOME_Exception );
 
+  // Concatenate the given meshes into one mesh
+  // Create the groups of all elements from initial meshes
+  SMESH::SMESH_Mesh_ptr ConcatenateWithGroups(const SMESH::mesh_array& theMeshesArray, 
+                                             CORBA::Boolean           theUniteIdenticalGroups, 
+                                             CORBA::Boolean           theMergeNodesAndElements, 
+                                             CORBA::Double            theMergeTolerance)
+    throw ( SALOME::SALOME_Exception );
 
   // ****************************************************
   // Interface inherited methods (from SALOMEDS::Driver)
 
   // ****************************************************
   // Interface inherited methods (from SALOMEDS::Driver)