Salome HOME
PR: synchro V6_main tag mergeto_V7_main_11Feb13
[modules/smesh.git] / src / PluginUtils / GeomSelectionTools.cxx
index a5297332461825677b8823e7c132b96f8e13c8e7..cfb841f5cca859b0e513c262743270af4d009f7d 100644 (file)
@@ -1,20 +1,20 @@
-//  Copyright (C) 2007-2010  CEA/DEN, EDF R&D
+// Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
 //
-//  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
 //
 
 // ---
@@ -33,6 +33,7 @@
 #include <SMESHGUI_Utils.h>
 #include <boost/shared_ptr.hpp>
 #include <GEOMImpl_Types.hxx>
+#include <GEOM_wrap.hxx>
 
 #include <TopoDS.hxx>
 #include <BRep_Tool.hxx>
@@ -219,17 +220,18 @@ TopAbs_ShapeEnum GeomSelectionTools::entryToShapeType(std::string entry){
       SalomeApp_Application* anApp = GetSalomeApplication();
       if (anApp) {
 //         MESSAGE("Got Application");
-        Engines::Component_var component = anApp->lcc()->FindOrLoad_Component( "FactoryServer","GEOM" );
+        Engines::EngineComponent_var component = anApp->lcc()->FindOrLoad_Component( "FactoryServer","GEOM" );
         GEOM::GEOM_Gen_var _geomEngine = GEOM::GEOM_Gen::_narrow(component);
 //         MESSAGE("Got GEOM engine");
         // if the Geom Object is a group
         if (aShape->GetType() == GEOM_GROUP){
-//           MESSAGE("It's a group");  
-          GEOM::GEOM_IGroupOperations_var aGroupOp = _geomEngine->GetIGroupOperations(myStudy->StudyId());
+//           MESSAGE("It's a group");
+          GEOM::GEOM_IGroupOperations_wrap aGroupOp =
+            _geomEngine->GetIGroupOperations(myStudy->StudyId());
           ShapeType= (TopAbs_ShapeEnum)aGroupOp->GetType(aShape);
-        } 
+        }
         // if not
-        else { 
+        else {
           GEOM_Client* aClient = new GEOM_Client();
           if ( aClient && !_geomEngine->_is_nil() ) {
 //             MESSAGE("GEOM client is OK and GEOM engine is not null");
@@ -274,7 +276,7 @@ GeomAbs_SurfaceType GeomSelectionTools::getFaceInformation(TopoDS_Shape S)
   if (!S.IsNull() &&  S.ShapeType()==TopAbs_FACE){
     TopoDS_Face f=TopoDS::Face(S);
     Handle(Geom_Surface) surf = BRep_Tool::Surface(f);
-    BRepAdaptor_Surface surf_adap=BRepAdaptor_Surface::BRepAdaptor_Surface(f);
+    BRepAdaptor_Surface surf_adap(f);
 
     /* Global Information */
     std::cout << "GLOBAL INFORMATION" << std::endl;
@@ -297,5 +299,46 @@ GeomAbs_SurfaceType GeomSelectionTools::getFaceInformation(TopoDS_Shape S)
 }
 
 
+//////////////////////////////////////////
+// Utility functions
+//////////////////////////////////////////
+#include <QLocale>
+#include <QRegExp>
+
+QString PluginUtils::PrintDoubleValue( double theValue, int thePrecision )
+{
+  const double prec = 1e-12;
+
+  if ( qAbs(theValue) < prec )
+    return "0";
 
+  QString aRes = QLocale().toString( theValue, thePrecision >= 0 ? 'f' : 'g', qAbs( thePrecision ) );
+
+  if ( prec > 0 ) {
+    int p = 0;
+    while ( p < thePrecision ) {
+      QString aRes = QLocale().toString( theValue, thePrecision >= 0 ? 'f' : 'g', qAbs( p++ ) );
+      double v = aRes.toDouble();
+      double err = qAbs( theValue - v );
+      if ( err > 0 && err <= prec )
+        break;
+    }
+  }
 
+  // remove trailing zeroes
+
+  QRegExp expre( QString( "(%1|%2)[+-]?[0-9]+$" ).arg( QLocale().exponential().toLower(),
+                               QLocale().exponential().toUpper() ) );
+
+  int idx = aRes.indexOf( expre );
+  QString aResExp = "";
+  if ( idx >= 0 ) {
+    aResExp = aRes.mid( idx );
+    aRes = aRes.left( idx );
+  }
+
+  if ( aRes.contains( QLocale().decimalPoint() ) )
+    aRes.remove( QRegExp( QString( "(\\%1|0)0*$" ).arg( QLocale().decimalPoint() ) ) );
+
+  return aRes == "-0" ? QString( "0" ) : aRes + aResExp;
+}