Salome HOME
Update copyright
[modules/smesh.git] / src / SMESH_I / SMESH_Group_i.cxx
index 7a75b310be55a430c394341c1e546a0483eb31c0..6c495af8ff8fe96461d9715600496c7a466dfe7f 100644 (file)
@@ -1,31 +1,30 @@
-//  SMESH SMESH_I : idl implementation based on 'SMESH' unit's classes
+// Copyright (C) 2007-2011  CEA/DEN, EDF R&D, OPEN CASCADE
 //
-//  Copyright (C) 2004  CEA
-// 
-//  This library is free software; you can redistribute it and/or 
-//  modify it under the terms of the GNU Lesser General Public 
-//  License as published by the Free Software Foundation; either 
-//  version 2.1 of the License. 
-// 
-//  This library is distributed in the hope that it will be useful, 
-//  but WITHOUT ANY WARRANTY; without even the implied warranty of 
-//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
-//  Lesser General Public License for more details. 
-// 
-//  You should have received a copy of the GNU Lesser General Public 
-//  License along with this library; if not, write to the Free Software 
-//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
-// 
-// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+// Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
 //
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
 //
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 //
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+//  SMESH SMESH_I : idl implementation based on 'SMESH' unit's classes
 //  File   : SMESH_Group_i.cxx
 //  Author : Sergey ANIKIN, OCC
 //  Module : SMESH
-//  $Header$
-
-
+//
 #include "SMESH_Group_i.hxx"
 #include "SMESH_Mesh_i.hxx"
 #include "SMESH_Gen_i.hxx"
@@ -37,6 +36,8 @@
 #include "SMESH_Filter_i.hxx"
 #include "SMESH_PythonDump.hxx"
 
+#include CORBA_SERVER_HEADER(SMESH_Filter)
+
 #include "utilities.h"
 
 using namespace SMESH;
@@ -61,14 +62,14 @@ SMESH_Group_i::SMESH_Group_i( PortableServer::POA_ptr thePOA, SMESH_Mesh_i* theM
      : SALOME::GenericObj_i( thePOA ),
        SMESH_GroupBase_i( thePOA, theMeshServant, theLocalID )
 {
-  MESSAGE("SMESH_Group_i; this = "<<this );
+  //MESSAGE("SMESH_Group_i; this = "<<this );
 }
 
 SMESH_GroupOnGeom_i::SMESH_GroupOnGeom_i( PortableServer::POA_ptr thePOA, SMESH_Mesh_i* theMeshServant, const int theLocalID )
      : SALOME::GenericObj_i( thePOA ),
        SMESH_GroupBase_i( thePOA, theMeshServant, theLocalID )
 {
-  MESSAGE("SMESH_GroupOnGeom_i; this = "<<this );
+  //MESSAGE("SMESH_GroupOnGeom_i; this = "<<this );
 }
 
 //=============================================================================
@@ -119,20 +120,24 @@ SMESHDS_GroupBase* SMESH_GroupBase_i::GetGroupDS() const
 
 void SMESH_GroupBase_i::SetName( const char* theName )
 {
-  // Update Python script
-  TPythonDump() <<  _this() << ".SetName( '" << theName << "' )";
-
   // Perform renaming
   ::SMESH_Group* aGroup = GetSmeshGroup();
-  if (aGroup) {
-    aGroup->SetName(theName);
-
-    // Update group name in a study
-    SMESH_Gen_i* aGen = myMeshServant->GetGen();
-    aGen->SetName( aGen->ObjectToSObject( aGen->GetCurrentStudy(), _this() ), theName );
+  if (!aGroup) {
+    MESSAGE("can't set name of a vague group");
     return;
   }
-  MESSAGE("can't set name of a vague group");
+
+  if ( aGroup->GetName() && !strcmp( aGroup->GetName(), theName ) )
+    return; // nothing to rename
+
+  aGroup->SetName(theName);
+
+  // Update group name in a study
+  SMESH_Gen_i* aGen = myMeshServant->GetGen();
+  aGen->SetName( aGen->ObjectToSObject( aGen->GetCurrentStudy(), _this() ), theName );
+  
+  // Update Python script
+  TPythonDump() <<  _this() << ".SetName( '" << theName << "' )";
 }
 
 //=============================================================================
@@ -163,11 +168,12 @@ SMESH::ElementType SMESH_GroupBase_i::GetType()
     SMDSAbs_ElementType aSMDSType = aGroupDS->GetType();
     SMESH::ElementType aType;
     switch (aSMDSType) {
-    case SMDSAbs_Node:   aType = SMESH::NODE; break;
-    case SMDSAbs_Edge:   aType = SMESH::EDGE; break;
-    case SMDSAbs_Face:   aType = SMESH::FACE; break;
-    case SMDSAbs_Volume: aType = SMESH::VOLUME; break;
-    default:             aType = SMESH::ALL; break;
+    case SMDSAbs_Node:      aType = SMESH::NODE;   break;
+    case SMDSAbs_Edge:      aType = SMESH::EDGE;   break;
+    case SMDSAbs_Face:      aType = SMESH::FACE;   break;
+    case SMDSAbs_Volume:    aType = SMESH::VOLUME; break;
+    case SMDSAbs_0DElement: aType = SMESH::ELEM0D; break;
+    default:                aType = SMESH::ALL;    break;
     }
     return aType;
   }
@@ -303,8 +309,8 @@ typedef bool (SMESHDS_Group::*TFunChangeGroup)(const int);
 
 CORBA::Long 
 ChangeByPredicate( SMESH::Predicate_i* thePredicate,
-                  SMESHDS_GroupBase* theGroupBase,
-                  TFunChangeGroup theFun)
+                   SMESHDS_GroupBase* theGroupBase,
+                   TFunChangeGroup theFun)
 {
   CORBA::Long aNb = 0;
   if(SMESHDS_Group* aGroupDS = dynamic_cast<SMESHDS_Group*>(theGroupBase)){
@@ -315,7 +321,7 @@ ChangeByPredicate( SMESH::Predicate_i* thePredicate,
     CORBA::Long i = 0, iEnd = aSequence.size();
     for(; i < iEnd; i++)
       if((aGroupDS->*theFun)(aSequence[i]))
-       aNb++;
+        aNb++;
     return aNb;
   }
   return aNb;
@@ -343,6 +349,37 @@ RemoveByPredicate( SMESH::Predicate_ptr thePredicate )
   return 0;
 }
 
+CORBA::Long SMESH_Group_i::AddFrom( SMESH::SMESH_IDSource_ptr theSource )
+{
+  long nbAdd = 0;
+  SMESHDS_Group* aGroupDS = dynamic_cast<SMESHDS_Group*>( GetGroupDS() );
+  if (aGroupDS) {
+    SMESH::long_array_var anIds;
+    SMESH::SMESH_GroupBase_var group = SMESH::SMESH_GroupBase::_narrow(theSource);
+    SMESH::SMESH_Mesh_var mesh       = SMESH::SMESH_Mesh::_narrow(theSource);
+    SMESH::SMESH_subMesh_var submesh = SMESH::SMESH_subMesh::_narrow(theSource);
+    SMESH::Filter_var filter         = SMESH::Filter::_narrow(theSource);
+    if ( !group->_is_nil())
+      anIds = group->GetType()==GetType() ? theSource->GetIDs() :  new SMESH::long_array();
+    else if ( !mesh->_is_nil() )
+      anIds = mesh->GetElementsByType( GetType() );
+    else if ( !submesh->_is_nil())
+      anIds = submesh->GetElementsByType( GetType() );
+    else if ( !filter->_is_nil() )
+      anIds = filter->GetElementType()==GetType() ? theSource->GetIDs() : new SMESH::long_array();
+    else 
+      anIds = theSource->GetIDs();
+    for ( int i = 0, total = anIds->length(); i < total; i++ ) {
+      if ( aGroupDS->Add((int)anIds[i]) ) nbAdd++;
+    }
+  }
+
+  // Update Python script
+  TPythonDump() << "nbAdd = " << _this() << ".AddFrom( " << theSource << " )";
+
+  return nbAdd;
+}
+
 //=============================================================================
 /*!
  *  
@@ -392,17 +429,6 @@ SMESH::SMESH_Mesh_ptr SMESH_GroupBase_i::GetMesh()
   return aMesh._retn();
 }
 
-//=============================================================================
-/*!
- *  
- */
-//=============================================================================
-SMESH::long_array* SMESH_GroupBase_i::GetIDs()
-{
-  SMESH::long_array_var aResult = GetListOfID();
-  return aResult._retn();
-}
-
 //=======================================================================
 //function : GetShape
 //purpose  : 
@@ -419,6 +445,44 @@ GEOM::GEOM_Object_ptr SMESH_GroupOnGeom_i::GetShape()
   return aGeomObj._retn();
 }
 
+//=============================================================================
+/*!
+ *
+ */
+//=============================================================================
+SALOMEDS::Color SMESH_GroupBase_i::GetColor()
+{
+  SMESHDS_GroupBase* aGroupDS = GetGroupDS();
+  if (aGroupDS)
+  {
+    Quantity_Color aQColor = aGroupDS->GetColor();
+    SALOMEDS::Color aColor;
+    aColor.R = aQColor.Red();
+    aColor.G = aQColor.Green();
+    aColor.B = aQColor.Blue();
+
+    return aColor;
+  }
+  MESSAGE("get color of a group");
+  return SALOMEDS::Color();
+}
+
+//=============================================================================
+/*!
+ *
+ */
+//=============================================================================
+void SMESH_GroupBase_i::SetColor(const SALOMEDS::Color& color)
+{
+  SMESHDS_GroupBase* aGroupDS = GetGroupDS();
+  if (aGroupDS)
+  {
+    Quantity_Color aQColor( color.R, color.G, color.B, Quantity_TOC_RGB );
+    aGroupDS->SetColor(aQColor);
+    TPythonDump()<<_this()<<".SetColor( SALOMEDS.Color( "<<color.R<<", "<<color.G<<", "<<color.B<<" ))";
+  }
+}
+
 //=============================================================================
 /*!
  *
@@ -429,7 +493,7 @@ CORBA::Long SMESH_GroupBase_i::GetColorNumber()
   SMESHDS_GroupBase* aGroupDS = GetGroupDS();
   if (aGroupDS)
     return aGroupDS->GetColorGroup();
-  MESSAGE("get color number of a vague group");
+  MESSAGE("get color number of a group");
   return 0;
 }
 
@@ -442,10 +506,59 @@ void SMESH_GroupBase_i::SetColorNumber(CORBA::Long color)
 {
   SMESHDS_GroupBase* aGroupDS = GetGroupDS();
   if (aGroupDS)
-    return aGroupDS->SetColorGroup(color);
-  MESSAGE("set color number of a vague group");
+  {
+    aGroupDS->SetColorGroup(color);
+    TPythonDump()<<_this()<<".SetColorGroup( "<<color<<" )";
+  }
+  MESSAGE("set color number of a group");
   return ;
 }
 
+//=============================================================================
+/*!
+ * Returns statistic of mesh elements
+ * Result array of number enityties
+ * Inherited from SMESH_IDSource
+ */
+//=============================================================================
+SMESH::long_array* SMESH_GroupBase_i::GetMeshInfo()
+{
+  SMESH::long_array_var aRes = new SMESH::long_array();
+  aRes->length(SMESH::Entity_Last);
+  for (int i = SMESH::Entity_Node; i < SMESH::Entity_Last; i++)
+    aRes[i] = 0;
+
+  SMESHDS_GroupBase* aGrpDS = GetGroupDS();
+  if ( !aGrpDS )
+    return aRes._retn();
+  if ( GetType() == NODE )
+    aRes[ SMESH::Entity_Node ] = aGrpDS->Extent();
+  else
+    SMESH_Mesh_i::CollectMeshInfo( aGrpDS->GetElements(), aRes);
+  return aRes._retn();
+}
+
+//=======================================================================
+//function : GetIDs
+//purpose  : Returns ids of members
+//=======================================================================
+
+SMESH::long_array* SMESH_GroupBase_i::GetIDs()
+{
+  SMESH::long_array_var aResult = GetListOfID();
+  return aResult._retn();
+}
+
+//=======================================================================
+//function : GetTypes
+//purpose  : Returns types of elements it contains
+//=======================================================================
 
+SMESH::array_of_ElementType* SMESH_GroupBase_i::GetTypes()
+{
+  SMESH::array_of_ElementType_var types = new SMESH::array_of_ElementType;
+  types->length( 1 );
+  types[0] = GetType();
+  return types._retn();
+}