Salome HOME
Merge from V6_main_20120808 08Aug12
[plugins/netgenplugin.git] / src / NETGENPlugin / NETGENPlugin_Hypothesis_i.cxx
index f13e9db5bd365942d6e1d774934654d5224a03e4..17bdd35a19da2d78ae6cf9f87a02460621ab5f59 100644 (file)
@@ -1,41 +1,56 @@
-//  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2012  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) 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 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.
+// 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
+// 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
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
+
 //  NETGENPlugin : C++ implementation
 // File      : NETGENPlugin_Hypothesis_i.cxx
 // Author    : Michael Sazonov (OCN)
 // Date      : 03/04/2006
 // Project   : SALOME
-// $Header$
 //=============================================================================
 //
 #include "NETGENPlugin_Hypothesis_i.hxx"
 #include "SMESH_Gen.hxx"
 #include "SMESH_PythonDump.hxx"
+#include "GEOM_Object.hxx"
 
 #include "Utils_CorbaException.hxx"
 #include "utilities.h"
 
 using namespace std;
 
+//=============================================================================
+/*!
+ *  Specialization of isToSetParameter<T> for double
+ */
+//=============================================================================
+
+template<>
+bool NETGENPlugin_Hypothesis_i::isToSetParameter<double>(double curValue,
+                                                         double newValue,
+                                                         /*SettingMethod*/int meth)
+{
+  return isToSetParameter(true, (fabs(curValue - newValue) < 1e-20), meth);
+}
+
 //=============================================================================
 /*!
  *  NETGENPlugin_Hypothesis_i::NETGENPlugin_Hypothesis_i
@@ -48,7 +63,8 @@ NETGENPlugin_Hypothesis_i (PortableServer::POA_ptr thePOA,
                            int                     theStudyId,
                            ::SMESH_Gen*            theGenImpl)
   : SALOME::GenericObj_i( thePOA ), 
-    SMESH_Hypothesis_i( thePOA )
+    SMESH_Hypothesis_i( thePOA ),
+    mySetMethodFlags(0)
 {
   MESSAGE( "NETGENPlugin_Hypothesis_i::NETGENPlugin_Hypothesis_i" );
   myBaseImpl = new ::NETGENPlugin_Hypothesis (theGenImpl->GetANewId(),
@@ -77,10 +93,11 @@ NETGENPlugin_Hypothesis_i::~NETGENPlugin_Hypothesis_i()
 //=============================================================================
 void NETGENPlugin_Hypothesis_i::SetMaxSize (CORBA::Double theValue)
 {
-  MESSAGE("NETGENPlugin_Hypothesis_i::SetMaxSize");
-  ASSERT(myBaseImpl);
-  this->GetImpl()->SetMaxSize(theValue);
-  SMESH::TPythonDump() << _this() << ".SetMaxSize( " << theValue << " )";
+  if ( isToSetParameter( GetMaxSize(), theValue, METH_SetMaxSize ))
+  {
+    this->GetImpl()->SetMaxSize(theValue);
+    SMESH::TPythonDump() << _this() << ".SetMaxSize( " << SMESH::TVar(theValue) << " )";
+  }
 }
 
 //=============================================================================
@@ -92,11 +109,37 @@ void NETGENPlugin_Hypothesis_i::SetMaxSize (CORBA::Double theValue)
 //=============================================================================
 CORBA::Double NETGENPlugin_Hypothesis_i::GetMaxSize()
 {
-  MESSAGE("NETGENPlugin_Hypothesis_i::GetMaxSize");
-  ASSERT(myBaseImpl);
   return this->GetImpl()->GetMaxSize();
 }
 
+//=============================================================================
+/*!
+ *  NETGENPlugin_Hypothesis_i::SetMinSize
+ *
+ *  Set MinSize
+ */
+//=============================================================================
+void NETGENPlugin_Hypothesis_i::SetMinSize (CORBA::Double theValue)
+{
+  if ( isToSetParameter( GetMinSize(), theValue, METH_SetMinSize ))
+  {
+    this->GetImpl()->SetMinSize(theValue);
+    SMESH::TPythonDump() << _this() << ".SetMinSize( " << SMESH::TVar(theValue) << " )";
+  }
+}
+
+//=============================================================================
+/*!
+ *  NETGENPlugin_Hypothesis_i::GetMinSize
+ *
+ *  Get MinSize
+ */
+//=============================================================================
+CORBA::Double NETGENPlugin_Hypothesis_i::GetMinSize()
+{
+  return this->GetImpl()->GetMinSize();
+}
+
 //=============================================================================
 /*!
  *  NETGENPlugin_Hypothesis_i::SetSecondOrder
@@ -106,10 +149,11 @@ CORBA::Double NETGENPlugin_Hypothesis_i::GetMaxSize()
 //=============================================================================
 void NETGENPlugin_Hypothesis_i::SetSecondOrder (CORBA::Boolean theValue)
 {
-  MESSAGE("NETGENPlugin_Hypothesis_i::SetSecondOrder");
-  ASSERT(myBaseImpl);
-  this->GetImpl()->SetSecondOrder(theValue);
-  SMESH::TPythonDump() << _this() << ".SetSecondOrder( " << theValue << " )";
+  if ( isToSetParameter( GetSecondOrder(), theValue, METH_SetSecondOrder ))
+  {
+    this->GetImpl()->SetSecondOrder(theValue);
+    SMESH::TPythonDump() << _this() << ".SetSecondOrder( " << theValue << " )";
+  }
 }
 
 //=============================================================================
@@ -121,8 +165,6 @@ void NETGENPlugin_Hypothesis_i::SetSecondOrder (CORBA::Boolean theValue)
 //=============================================================================
 CORBA::Boolean NETGENPlugin_Hypothesis_i::GetSecondOrder()
 {
-  MESSAGE("NETGENPlugin_Hypothesis_i::GetSecondOrder");
-  ASSERT(myBaseImpl);
   return this->GetImpl()->GetSecondOrder();
 }
 
@@ -135,10 +177,11 @@ CORBA::Boolean NETGENPlugin_Hypothesis_i::GetSecondOrder()
 //=============================================================================
 void NETGENPlugin_Hypothesis_i::SetOptimize (CORBA::Boolean theValue)
 {
-  MESSAGE("NETGENPlugin_Hypothesis_i::SetOptimize");
-  ASSERT(myBaseImpl);
-  this->GetImpl()->SetOptimize(theValue);
-  SMESH::TPythonDump() << _this() << ".SetOptimize( " << theValue << " )";
+  if ( isToSetParameter( GetOptimize(), theValue, METH_SetOptimize ))
+  {
+    this->GetImpl()->SetOptimize(theValue);
+    SMESH::TPythonDump() << _this() << ".SetOptimize( " << theValue << " )";
+  }
 }
 
 //=============================================================================
@@ -150,8 +193,6 @@ void NETGENPlugin_Hypothesis_i::SetOptimize (CORBA::Boolean theValue)
 //=============================================================================
 CORBA::Boolean NETGENPlugin_Hypothesis_i::GetOptimize()
 {
-  MESSAGE("NETGENPlugin_Hypothesis_i::GetOptimize");
-  ASSERT(myBaseImpl);
   return this->GetImpl()->GetOptimize();
 }
 
@@ -164,10 +205,11 @@ CORBA::Boolean NETGENPlugin_Hypothesis_i::GetOptimize()
 //=============================================================================
 void NETGENPlugin_Hypothesis_i::SetFineness (CORBA::Long theValue)
 {
-  MESSAGE("NETGENPlugin_Hypothesis_i::SetFineness");
-  ASSERT(myBaseImpl);
-  this->GetImpl()->SetFineness((::NETGENPlugin_Hypothesis::Fineness)theValue);
-  SMESH::TPythonDump() << _this() << ".SetFineness( " << theValue << " )";
+  if ( isToSetParameter( GetFineness(), theValue, METH_SetFineness ))
+  {
+    this->GetImpl()->SetFineness((::NETGENPlugin_Hypothesis::Fineness)theValue);
+    SMESH::TPythonDump() << _this() << ".SetFineness( " << theValue << " )";
+  }
 }
 
 //=============================================================================
@@ -179,8 +221,6 @@ void NETGENPlugin_Hypothesis_i::SetFineness (CORBA::Long theValue)
 //=============================================================================
 CORBA::Long NETGENPlugin_Hypothesis_i::GetFineness()
 {
-  MESSAGE("NETGENPlugin_Hypothesis_i::GetFineness");
-  ASSERT(myBaseImpl);
   return this->GetImpl()->GetFineness();
 }
 
@@ -193,10 +233,11 @@ CORBA::Long NETGENPlugin_Hypothesis_i::GetFineness()
 //=============================================================================
 void NETGENPlugin_Hypothesis_i::SetGrowthRate (CORBA::Double theValue)
 {
-  MESSAGE("NETGENPlugin_Hypothesis_i::SetGrowthRate");
-  ASSERT(myBaseImpl);
-  this->GetImpl()->SetGrowthRate(theValue);
-  SMESH::TPythonDump() << _this() << ".SetGrowthRate( " << theValue << " )";
+  if ( isToSetParameter( GetGrowthRate(), theValue, METH_SetGrowthRate ))
+  {
+    this->GetImpl()->SetGrowthRate(theValue);
+    SMESH::TPythonDump() << _this() << ".SetGrowthRate( " << SMESH::TVar(theValue) << " )";
+  }
 }
 
 //=============================================================================
@@ -208,8 +249,6 @@ void NETGENPlugin_Hypothesis_i::SetGrowthRate (CORBA::Double theValue)
 //=============================================================================
 CORBA::Double NETGENPlugin_Hypothesis_i::GetGrowthRate()
 {
-  MESSAGE("NETGENPlugin_Hypothesis_i::GetGrowthRate");
-  ASSERT(myBaseImpl);
   return this->GetImpl()->GetGrowthRate();
 }
 
@@ -222,10 +261,11 @@ CORBA::Double NETGENPlugin_Hypothesis_i::GetGrowthRate()
 //=============================================================================
 void NETGENPlugin_Hypothesis_i::SetNbSegPerEdge (CORBA::Double theValue)
 {
-  MESSAGE("NETGENPlugin_Hypothesis_i::SetNbSegPerEdge");
-  ASSERT(myBaseImpl);
-  this->GetImpl()->SetNbSegPerEdge(theValue);
-  SMESH::TPythonDump() << _this() << ".SetNbSegPerEdge( " << theValue << " )";
+  if ( isToSetParameter( GetNbSegPerEdge(), theValue, METH_SetNbSegPerEdge ))
+  {
+    this->GetImpl()->SetNbSegPerEdge(theValue);
+    SMESH::TPythonDump() << _this() << ".SetNbSegPerEdge( " << SMESH::TVar(theValue) << " )";
+  }
 }
 
 //=============================================================================
@@ -237,8 +277,6 @@ void NETGENPlugin_Hypothesis_i::SetNbSegPerEdge (CORBA::Double theValue)
 //=============================================================================
 CORBA::Double NETGENPlugin_Hypothesis_i::GetNbSegPerEdge()
 {
-  MESSAGE("NETGENPlugin_Hypothesis_i::GetNbSegPerEdge");
-  ASSERT(myBaseImpl);
   return this->GetImpl()->GetNbSegPerEdge();
 }
 
@@ -251,10 +289,11 @@ CORBA::Double NETGENPlugin_Hypothesis_i::GetNbSegPerEdge()
 //=============================================================================
 void NETGENPlugin_Hypothesis_i::SetNbSegPerRadius (CORBA::Double theValue)
 {
-  MESSAGE("NETGENPlugin_Hypothesis_i::SetNbSegPerRadius");
-  ASSERT(myBaseImpl);
-  this->GetImpl()->SetNbSegPerRadius(theValue);
-  SMESH::TPythonDump() << _this() << ".SetNbSegPerRadius( " << theValue << " )";
+  if ( isToSetParameter( GetNbSegPerRadius(), theValue, METH_SetNbSegPerRadius ))
+  {
+    this->GetImpl()->SetNbSegPerRadius(theValue);
+    SMESH::TPythonDump() << _this() << ".SetNbSegPerRadius( " << SMESH::TVar(theValue) << " )";
+  }
 }
 
 //=============================================================================
@@ -266,11 +305,84 @@ void NETGENPlugin_Hypothesis_i::SetNbSegPerRadius (CORBA::Double theValue)
 //=============================================================================
 CORBA::Double NETGENPlugin_Hypothesis_i::GetNbSegPerRadius()
 {
-  MESSAGE("NETGENPlugin_Hypothesis_i::GetNbSegPerRadius");
-  ASSERT(myBaseImpl);
   return this->GetImpl()->GetNbSegPerRadius();
 }
 
+//=============================================================================
+
+void NETGENPlugin_Hypothesis_i::SetLocalSizeOnShape(GEOM::GEOM_Object_ptr GeomObj,
+                                                    CORBA::Double         localSize)
+{
+  string entry;
+  entry = GeomObj->GetStudyEntry();
+  SetLocalSizeOnEntry(entry.c_str(), localSize);
+}
+
+//=============================================================================
+
+void NETGENPlugin_Hypothesis_i::SetLocalSizeOnEntry(const char*   entry,
+                                                    CORBA::Double localSize)
+{
+  if ( isToSetParameter( GetLocalSizeOnEntry(entry), localSize, METH_SetLocalSizeOnEntry ))
+  {
+    this->GetImpl()->SetLocalSizeOnEntry(entry, localSize);
+    SMESH::TPythonDump()
+      << _this() << ".SetLocalSizeOnShape(" << entry << ", " << localSize << ")";
+  }
+}
+
+//=============================================================================
+
+CORBA::Double NETGENPlugin_Hypothesis_i::GetLocalSizeOnEntry(const char* entry)
+{
+  return this->GetImpl()->GetLocalSizeOnEntry(entry);
+}
+
+//=============================================================================
+
+NETGENPlugin::string_array* NETGENPlugin_Hypothesis_i::GetLocalSizeEntries()
+{
+  NETGENPlugin::string_array_var result = new NETGENPlugin::string_array();
+  const ::NETGENPlugin_Hypothesis::TLocalSize localSizes =
+    this->GetImpl()->GetLocalSizesAndEntries();
+  result->length(localSizes.size());
+  ::NETGENPlugin_Hypothesis::TLocalSize::const_iterator it = localSizes.begin();
+  for (int i=0 ; it != localSizes.end() ; i++, it++)
+    {
+      string entry = (*it).first;
+      result[i] = CORBA::string_dup(entry.c_str());
+    }
+  return result._retn();
+}
+
+//=============================================================================
+
+void NETGENPlugin_Hypothesis_i::UnsetLocalSizeOnEntry(const char* entry)
+{
+  this->GetImpl()->UnsetLocalSizeOnEntry(entry);
+  SMESH::TPythonDump() << _this() << ".UnsetLocalSizeOnEntry(" << entry << ")";
+}
+
+//=============================================================================
+
+void NETGENPlugin_Hypothesis_i::SetQuadAllowed (CORBA::Boolean theValue)
+{
+  if ( NETGENPlugin_Hypothesis_i::isToSetParameter( GetQuadAllowed(),
+                                                    theValue,
+                                                    METH_SetQuadAllowed ))
+  {
+    this->GetImpl()->SetQuadAllowed(theValue);
+    SMESH::TPythonDump() << _this() << ".SetQuadAllowed( " << theValue << " )";
+  }
+}
+
+//=============================================================================
+
+CORBA::Boolean NETGENPlugin_Hypothesis_i::GetQuadAllowed()
+{
+  return this->GetImpl()->GetQuadAllowed();
+}
+
 //=============================================================================
 /*!
  *  NETGENPlugin_Hypothesis_i::GetImpl
@@ -280,7 +392,6 @@ CORBA::Double NETGENPlugin_Hypothesis_i::GetNbSegPerRadius()
 //=============================================================================
 ::NETGENPlugin_Hypothesis* NETGENPlugin_Hypothesis_i::GetImpl()
 {
-  MESSAGE("NETGENPlugin_Hypothesis_i::GetImpl");
   return (::NETGENPlugin_Hypothesis*)myBaseImpl;
 }
 
@@ -297,3 +408,42 @@ CORBA::Boolean NETGENPlugin_Hypothesis_i::IsDimSupported( SMESH::Dimension type
 {
   return type == SMESH::DIM_3D;
 }
+
+//================================================================================
+/*!
+ * \brief method intended to remove explicit treatment of Netgen hypotheses from SMESH_NoteBook
+ */
+//================================================================================
+
+int NETGENPlugin_Hypothesis_i::getParamIndex(const TCollection_AsciiString& method,
+                                             int nbVars) const
+{
+  if ( method == "SetMaxSize"        ) return 0;
+  if ( method == "SetGrowthRate"     ) return 1;
+  if ( method == "SetNbSegPerEdge"   ) return 2;
+  if ( method == "SetNbSegPerRadius" ) return 3;
+  if ( method == "SetMinSize" )        return nbVars-1;
+
+  return SMESH_Hypothesis_i::getParamIndex( method, nbVars ); // return default value
+}
+
+//================================================================================
+/*!
+ * \brief Method used to convert variable parameters stored in an old study
+ * into myMethod2VarParams. It should return a method name for an index of
+ * variable parameters. Index is countered from zero
+ */
+//================================================================================
+
+std::string NETGENPlugin_Hypothesis_i::getMethodOfParameter(const int paramIndex,
+                                                            int nbVars) const
+{
+  switch ( paramIndex ) {
+  case 0: return "SetMaxSize";
+  case 1: return nbVars == 2 ? "SetMinSize" : "SetGrowthRate";
+  case 2: return "SetNbSegPerEdge";
+  case 3: return "SetNbSegPerRadius";
+  case 4: return "SetMinSize";
+  }
+  return "";
+}