X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FPluginUtils%2FGeomSelectionTools.cxx;h=cfb841f5cca859b0e513c262743270af4d009f7d;hb=20c126bc220757c06b5576f71ed6f34ae85e3e40;hp=ceafd175ddbb87463883de8c6105495e0bf2c1e4;hpb=dd7baabfa15bd0d536f2f0b5fea6cc1a1b73fc8d;p=modules%2Fsmesh.git diff --git a/src/PluginUtils/GeomSelectionTools.cxx b/src/PluginUtils/GeomSelectionTools.cxx index ceafd175d..cfb841f5c 100644 --- a/src/PluginUtils/GeomSelectionTools.cxx +++ b/src/PluginUtils/GeomSelectionTools.cxx @@ -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 #include #include +#include #include #include @@ -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"); @@ -297,5 +299,46 @@ GeomAbs_SurfaceType GeomSelectionTools::getFaceInformation(TopoDS_Shape S) } +////////////////////////////////////////// +// Utility functions +////////////////////////////////////////// +#include +#include + +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; +}