Salome HOME
IPAL21286 1D Meshing for the Forward and Reversed Edge are equal.
[modules/smesh.git] / src / SMESH_I / SMESH_Group_i.cxx
index 78ca5289810b95a4fb690ab38ca20f4365136ebf..045e691b9c79315a0a32e7c1125b73fa8661fe18 100644 (file)
@@ -1,31 +1,29 @@
-//  SMESH SMESH_I : idl implementation based on 'SMESH' unit's classes
+//  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
+//
+//  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+//  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
 //
-//  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.org 
+//  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"
 #include "SMESHDS_Group.hxx"
 #include "SMESHDS_GroupOnGeom.hxx"
 #include "SMDSAbs_ElementType.hxx"
+
+#include "SMESH_Filter_i.hxx"
+#include "SMESH_PythonDump.hxx"
+
 #include "utilities.h"
 
+using namespace SMESH;
+
 //=============================================================================
 /*!
  *  
@@ -55,14 +59,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 );
 }
 
 //=============================================================================
@@ -113,16 +117,24 @@ SMESHDS_GroupBase* SMESH_GroupBase_i::GetGroupDS() const
 
 void SMESH_GroupBase_i::SetName( const char* 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 << "' )";
 }
 
 //=============================================================================
@@ -204,6 +216,10 @@ CORBA::Boolean SMESH_GroupBase_i::IsEmpty()
 
 void SMESH_Group_i::Clear()
 {
+  // Update Python script
+  TPythonDump() << _this() << ".Clear()";
+
+  // Clear the group
   SMESHDS_Group* aGroupDS = dynamic_cast<SMESHDS_Group*>( GetGroupDS() );
   if (aGroupDS) {
     aGroupDS->Clear();
@@ -235,6 +251,10 @@ CORBA::Boolean SMESH_GroupBase_i::Contains( CORBA::Long theID )
 
 CORBA::Long SMESH_Group_i::Add( const SMESH::long_array& theIDs )
 {
+  // Update Python script
+  TPythonDump() << "nbAdd = " << _this() << ".Add( " << theIDs << " )";
+
+  // Add elements to the group
   SMESHDS_Group* aGroupDS = dynamic_cast<SMESHDS_Group*>( GetGroupDS() );
   if (aGroupDS) {
     int nbAdd = 0;
@@ -255,6 +275,82 @@ CORBA::Long SMESH_Group_i::Add( const SMESH::long_array& theIDs )
  */
 //=============================================================================
 
+CORBA::Long SMESH_Group_i::Remove( const SMESH::long_array& theIDs )
+{
+  // Update Python script
+  TPythonDump() << "nbDel = " << _this() << ".Remove( " << theIDs << " )";
+
+  // Remove elements from the group
+  SMESHDS_Group* aGroupDS = dynamic_cast<SMESHDS_Group*>( GetGroupDS() );
+  if (aGroupDS) {
+    int nbDel = 0;
+    for (int i = 0; i < theIDs.length(); i++) {
+      int anID = (int) theIDs[i];
+      if (aGroupDS->Remove(anID))
+        nbDel++;
+    }
+    return nbDel;
+  }
+  MESSAGE("attempt to remove elements from a vague group");
+  return 0;
+}
+
+//=============================================================================
+/*!
+ *  
+ */
+//=============================================================================
+
+typedef bool (SMESHDS_Group::*TFunChangeGroup)(const int);
+
+CORBA::Long 
+ChangeByPredicate( SMESH::Predicate_i* thePredicate,
+                  SMESHDS_GroupBase* theGroupBase,
+                  TFunChangeGroup theFun)
+{
+  CORBA::Long aNb = 0;
+  if(SMESHDS_Group* aGroupDS = dynamic_cast<SMESHDS_Group*>(theGroupBase)){
+    SMESH::Controls::Filter::TIdSequence aSequence;
+    const SMDS_Mesh* aMesh = theGroupBase->GetMesh();
+    SMESH::Filter_i::GetElementsId(thePredicate,aMesh,aSequence);
+    
+    CORBA::Long i = 0, iEnd = aSequence.size();
+    for(; i < iEnd; i++)
+      if((aGroupDS->*theFun)(aSequence[i]))
+       aNb++;
+    return aNb;
+  }
+  return aNb;
+}
+
+CORBA::Long 
+SMESH_Group_i::
+AddByPredicate( SMESH::Predicate_ptr thePredicate )
+{
+  if(SMESH::Predicate_i* aPredicate = SMESH::GetPredicate(thePredicate)){
+    TPythonDump()<<_this()<<".AddByPredicate("<<aPredicate<<")";
+    return ChangeByPredicate(aPredicate,GetGroupDS(),&SMESHDS_Group::Add);
+  }
+  return 0;
+}
+
+CORBA::Long 
+SMESH_Group_i::
+RemoveByPredicate( SMESH::Predicate_ptr thePredicate )
+{
+  if(SMESH::Predicate_i* aPredicate = SMESH::GetPredicate(thePredicate)){
+    TPythonDump()<<_this()<<".RemoveByPredicate("<<aPredicate<<")";
+    return ChangeByPredicate(aPredicate,GetGroupDS(),&SMESHDS_Group::Remove);
+  }
+  return 0;
+}
+
+//=============================================================================
+/*!
+ *  
+ */
+//=============================================================================
+
 CORBA::Long SMESH_GroupBase_i::GetID( CORBA::Long theIndex )
 {
   SMESHDS_GroupBase* aGroupDS = GetGroupDS();
@@ -285,28 +381,6 @@ SMESH::long_array* SMESH_GroupBase_i::GetListOfID()
   return aRes._retn();
 }
 
-//=============================================================================
-/*!
- *  
- */
-//=============================================================================
-
-CORBA::Long SMESH_Group_i::Remove( const SMESH::long_array& theIDs )
-{
-  SMESHDS_Group* aGroupDS = dynamic_cast<SMESHDS_Group*>( GetGroupDS() );
-  if (aGroupDS) {
-    int nbDel = 0;
-    for (int i = 0; i < theIDs.length(); i++) {
-      int anID = (int) theIDs[i];
-      if (aGroupDS->Remove(anID))
-        nbDel++;
-    }
-    return nbDel;
-  }
-  MESSAGE("attempt to remove elements from a vague group");
-  return 0;
-}
-
 //=============================================================================
 /*!
  *  
@@ -347,3 +421,69 @@ 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 );
+    return aGroupDS->SetColor(aQColor);
+  }
+  MESSAGE("set color of a group");
+  return ;
+}
+
+//=============================================================================
+/*!
+ *
+ */
+//=============================================================================
+CORBA::Long SMESH_GroupBase_i::GetColorNumber()
+{
+  SMESHDS_GroupBase* aGroupDS = GetGroupDS();
+  if (aGroupDS)
+    return aGroupDS->GetColorGroup();
+  MESSAGE("get color number of a group");
+  return 0;
+}
+
+//=============================================================================
+/*!
+ *
+ */
+//=============================================================================
+void SMESH_GroupBase_i::SetColorNumber(CORBA::Long color)
+{
+  SMESHDS_GroupBase* aGroupDS = GetGroupDS();
+  if (aGroupDS)
+    return aGroupDS->SetColorGroup(color);
+  MESSAGE("set color number of a group");
+  return ;
+}