Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include "GeomSelectionTools.h"
00026
00027 #include <LightApp_SelectionMgr.h>
00028 #include <SalomeApp_Application.h>
00029 #include <SUIT_Session.h>
00030
00031 #include <SALOME_ListIteratorOfListIO.hxx>
00032 #include <GEOM_Client.hxx>
00033 #include <SMESHGUI_Utils.h>
00034 #include <boost/shared_ptr.hpp>
00035 #include <GEOMImpl_Types.hxx>
00036
00037 #include <TopoDS.hxx>
00038 #include <BRep_Tool.hxx>
00039 #include <Handle_Geom_Surface.hxx>
00040 #include <BRepAdaptor_Surface.hxx>
00041
00042 #include "utilities.h"
00043
00044 #include "SALOME_LifeCycleCORBA.hxx"
00045 #include <sstream>
00046
00052 GeomSelectionTools::GeomSelectionTools(_PTR(Study) aStudy)
00053 {
00054 myStudy = aStudy;
00055 }
00056
00061 _PTR(Study) GeomSelectionTools::getMyStudy()
00062 {
00063 return myStudy;
00064 }
00065
00070 SalomeApp_Application* GeomSelectionTools::GetSalomeApplication()
00071 {
00072 SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
00073 if (anApp)
00074 return anApp;
00075 else
00076 return 0;
00077 }
00078
00083 LightApp_SelectionMgr* GeomSelectionTools::selectionMgr()
00084 {
00085 SalomeApp_Application* anApp = GetSalomeApplication();
00086 if (anApp)
00087 return dynamic_cast<LightApp_SelectionMgr*>( anApp->selectionMgr() );
00088 else
00089 return 0;
00090 }
00091
00096 SALOME_ListIO* GeomSelectionTools::getSelectedSalomeObjects()
00097 {
00098 SALOME_ListIO* selected;
00099 LightApp_SelectionMgr* aSel = selectionMgr();
00100 aSel->selectedObjects( *selected, NULL, false );
00101 return selected;
00102 }
00103
00108 Handle(SALOME_InteractiveObject) GeomSelectionTools::getFirstSelectedSalomeObject()
00109 {
00110 SALOME_ListIO selected;
00111 LightApp_SelectionMgr* aSel = selectionMgr();
00112 aSel->selectedObjects( selected, NULL, false );
00113 if (!selected.IsEmpty()){
00114 SALOME_ListIteratorOfListIO anIt(selected);
00115 Handle(SALOME_InteractiveObject) anIO;
00116 anIO = anIt.Value();
00117 return anIO;
00118 }
00119 return NULL;
00120 }
00121
00126 std::string GeomSelectionTools::getFirstSelectedEntry()
00127 {
00128 Handle(SALOME_InteractiveObject) anIO;
00129 std::string entry="";
00130 anIO=GeomSelectionTools::getFirstSelectedSalomeObject();
00131 return GeomSelectionTools::getEntryOfObject(anIO);
00132 }
00133
00139 std::string GeomSelectionTools::getEntryOfObject(Handle(SALOME_InteractiveObject) anIO){
00140 std::string entry="";
00141 _PTR(SObject) aSO = myStudy->FindObjectID(anIO->getEntry());
00142 if (aSO){
00143 _PTR(SObject) aRefSObj;
00144
00145 if ( aSO->ReferencedObject( aRefSObj ))
00146 entry = aRefSObj->GetID();
00147
00148 else
00149 entry= anIO->getEntry();
00150 }
00151 return entry;
00152 }
00153
00159 std::string GeomSelectionTools::getNameFromEntry(std::string entry){
00160 std::string name = "";
00161 _PTR(SObject) aSO = myStudy->FindObjectID(entry);
00162 if (aSO){
00163 _PTR(SObject) aRefSObj;
00164
00165 if ( aSO->ReferencedObject( aRefSObj ))
00166 name = aRefSObj->GetName();
00167
00168 else
00169 name = aSO->GetName();
00170 }
00171 return name;
00172 }
00173
00174
00179 std::string GeomSelectionTools::getFirstSelectedComponentDataType()
00180 {
00181 Handle(SALOME_InteractiveObject) anIO;
00182 std::string DataType="";
00183 anIO=GeomSelectionTools::getFirstSelectedSalomeObject();
00184 _PTR(SObject) aSO = myStudy->FindObjectID(anIO->getEntry());
00185 if (aSO){
00186 _PTR(SObject) aRefSObj;
00187
00188 if ( aSO->ReferencedObject( aRefSObj ))
00189 DataType= aRefSObj->GetFatherComponent()->ComponentDataType();
00190
00191 else
00192 DataType=anIO->getComponentDataType();
00193 }
00194 return DataType;
00195 }
00196
00201 TopAbs_ShapeEnum GeomSelectionTools::entryToShapeType(std::string entry){
00202
00203 TopoDS_Shape S = TopoDS_Shape();
00204 TopAbs_ShapeEnum ShapeType = TopAbs_SHAPE;
00205 _PTR(SObject) aSO = myStudy->FindObjectID(entry);
00206 if (aSO){
00207 _PTR(SObject) aRefSObj;
00208 GEOM::GEOM_Object_var aShape;
00209
00210
00211 if ( aSO->ReferencedObject( aRefSObj ))
00212 aSO = aRefSObj;
00213
00214 if ( strcmp(aSO->GetFatherComponent()->ComponentDataType().c_str(),"GEOM") == 0)
00215 aShape = SMESH::SObjectToInterface<GEOM::GEOM_Object>(aSO);
00216 if ( !aShape->_is_nil() ){
00217
00218
00219 SalomeApp_Application* anApp = GetSalomeApplication();
00220 if (anApp) {
00221
00222 Engines::EngineComponent_var component = anApp->lcc()->FindOrLoad_Component( "FactoryServer","GEOM" );
00223 GEOM::GEOM_Gen_var _geomEngine = GEOM::GEOM_Gen::_narrow(component);
00224
00225
00226 if (aShape->GetType() == GEOM_GROUP){
00227
00228 GEOM::GEOM_IGroupOperations_var aGroupOp = _geomEngine->GetIGroupOperations(myStudy->StudyId());
00229 ShapeType= (TopAbs_ShapeEnum)aGroupOp->GetType(aShape);
00230 }
00231
00232 else {
00233 GEOM_Client* aClient = new GEOM_Client();
00234 if ( aClient && !_geomEngine->_is_nil() ) {
00235
00236 S = aClient->GetShape( _geomEngine, aShape );
00237 ShapeType=S.ShapeType();
00238 }
00239 }
00240 }
00241 }
00242 }
00243
00244 return ShapeType;
00245 }
00246
00251 TopAbs_ShapeEnum GeomSelectionTools:: getFirstSelectedShapeType()
00252 {
00253 Handle(SALOME_InteractiveObject) anIO;
00254 anIO=GeomSelectionTools::getFirstSelectedSalomeObject();
00255 return entryToShapeType(anIO->getEntry());
00256 }
00257
00271 GeomAbs_SurfaceType GeomSelectionTools::getFaceInformation(TopoDS_Shape S)
00272 {
00273 GeomAbs_SurfaceType surf_type=GeomAbs_OtherSurface ;
00274 if (!S.IsNull() && S.ShapeType()==TopAbs_FACE){
00275 TopoDS_Face f=TopoDS::Face(S);
00276 Handle(Geom_Surface) surf = BRep_Tool::Surface(f);
00277 BRepAdaptor_Surface surf_adap(f);
00278
00279
00280 std::cout << "GLOBAL INFORMATION" << std::endl;
00281 std::cout << "******************" << std::endl;
00282 std::stringstream buffer;
00283 buffer << "Degre U : " << surf_adap.UDegree();
00284
00285 std::cout << buffer.str() << std::endl;
00286 std::cout << " Degre V : " << surf_adap.VDegree() << std::endl;
00287 std::cout << " Nb Poles U : " << surf_adap.NbUPoles() << std::endl;
00288 std::cout << " Nb Poles V : " << surf_adap.NbVPoles() << std::endl;
00289 std::cout << " Nb Noeuds U : " << surf_adap.NbUKnots() << std::endl;
00290 std::cout << " Nb Noeuds V : " << surf_adap.NbVKnots() << std::endl;
00291 std::cout << " U Rationnel ? " << surf_adap.IsURational() << std::endl;
00292 std::cout << " V Rationnel ? " << surf_adap.IsVRational() << std::endl;
00293
00294 surf_type=surf_adap.GetType();
00295 }
00296 return surf_type;
00297 }
00298
00299
00301
00303 #include <QLocale>
00304 #include <QRegExp>
00305
00306 QString PluginUtils::PrintDoubleValue( double theValue, int thePrecision )
00307 {
00308 const double prec = 1e-12;
00309
00310 if ( qAbs(theValue) < prec )
00311 return "0";
00312
00313 QString aRes = QLocale().toString( theValue, thePrecision >= 0 ? 'f' : 'g', qAbs( thePrecision ) );
00314
00315 if ( prec > 0 ) {
00316 int p = 0;
00317 while ( p < thePrecision ) {
00318 QString aRes = QLocale().toString( theValue, thePrecision >= 0 ? 'f' : 'g', qAbs( p++ ) );
00319 double v = aRes.toDouble();
00320 double err = qAbs( theValue - v );
00321 if ( err > 0 && err <= prec )
00322 break;
00323 }
00324 }
00325
00326
00327
00328 QRegExp expre( QString( "(%1|%2)[+-]?[0-9]+$" ).arg( QLocale().exponential().toLower(),
00329 QLocale().exponential().toUpper() ) );
00330
00331 int idx = aRes.indexOf( expre );
00332 QString aResExp = "";
00333 if ( idx >= 0 ) {
00334 aResExp = aRes.mid( idx );
00335 aRes = aRes.left( idx );
00336 }
00337
00338 if ( aRes.contains( QLocale().decimalPoint() ) )
00339 aRes.remove( QRegExp( QString( "(\\%1|0)0*$" ).arg( QLocale().decimalPoint() ) ) );
00340
00341 return aRes == "-0" ? QString( "0" ) : aRes + aResExp;
00342 }