From: jfa Date: Tue, 13 Sep 2005 11:09:57 +0000 (+0000) Subject: Small code improvements X-Git-Tag: V3_1_0a1~4 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=168917eddd31331d7cb516c64ffd781f86aa99ba;p=modules%2Fgeom.git Small code improvements --- diff --git a/src/GEOMGUI/GEOM_Displayer.cxx b/src/GEOMGUI/GEOM_Displayer.cxx index 26313ac05..18a2df6ec 100644 --- a/src/GEOMGUI/GEOM_Displayer.cxx +++ b/src/GEOMGUI/GEOM_Displayer.cxx @@ -167,7 +167,7 @@ SUIT_SelectionFilter* GEOM_Displayer::getFilter( const int theMode ) // Function : getEntry // Purpose : //================================================================ -static char* getEntry( GEOM::GEOM_Object_ptr object ) +static string getEntry( GEOM::GEOM_Object_ptr object ) { SUIT_Session* session = SUIT_Session::session(); SalomeApp_Application* app = dynamic_cast( session->activeApplication() ); @@ -179,7 +179,7 @@ static char* getEntry( GEOM::GEOM_Object_ptr object ) SalomeApp_Study* study = ( SalomeApp_Study* )app->activeStudy(); _PTR(SObject) SO ( study->studyDS()->FindObjectIOR( IOR ) ); if ( SO ) - return (char*)(SO->GetID().c_str()); + return SO->GetID(); } } return ""; @@ -189,7 +189,7 @@ static char* getEntry( GEOM::GEOM_Object_ptr object ) // Function : getName // Purpose : //================================================================ -static const char* getName( GEOM::GEOM_Object_ptr object ) +static string getName( GEOM::GEOM_Object_ptr object ) { SUIT_Session* session = SUIT_Session::session(); SalomeApp_Application* app = dynamic_cast( session->activeApplication() ); @@ -206,7 +206,7 @@ static const char* getName( GEOM::GEOM_Object_ptr object ) if ( aSObj && aSObj->FindAttribute( anAttr, "AttributeName") ) { _PTR(AttributeName) aNameAttr( anAttr ); - return aNameAttr->Value().c_str(); + return aNameAttr->Value(); } } } @@ -319,8 +319,8 @@ void GEOM_Displayer::Display( GEOM::GEOM_Object_ptr theObj, const bool updateVie string entry = getEntry( theObj ); if ( entry != "" ) { - Display( new SALOME_InteractiveObject( - entry.c_str(), "GEOM", strdup( getName( theObj ) ) ), updateViewer ); + Display(new SALOME_InteractiveObject(entry.c_str(), "GEOM", getName(theObj).c_str()), + updateViewer); } } @@ -364,8 +364,8 @@ void GEOM_Displayer::Erase( GEOM::GEOM_Object_ptr theObj, string entry = getEntry( theObj ); if ( entry != "" ) { - Erase( new SALOME_InteractiveObject( - entry.c_str(), "GEOM", strdup( getName( theObj ) ) ), forced, updateViewer ); + Erase(new SALOME_InteractiveObject(entry.c_str(), "GEOM", getName(theObj).c_str()), + forced, updateViewer); } } @@ -1116,4 +1116,3 @@ void GEOM_Displayer::clearTemporary( SalomeApp_SelectionMgr* theSelMgr ) theSelMgr->setSelectedObjects( toSelect, true ); } - diff --git a/src/GEOMToolsGUI/GEOMToolsGUI.cxx b/src/GEOMToolsGUI/GEOMToolsGUI.cxx index aced45d1a..b99699407 100644 --- a/src/GEOMToolsGUI/GEOMToolsGUI.cxx +++ b/src/GEOMToolsGUI/GEOMToolsGUI.cxx @@ -349,7 +349,7 @@ void GEOMToolsGUI::OnEditDelete() } // if ( selected not empty ) } // if ( selMgr && appStudy ) - app->updateActions(); //SRN: To update a Save button in the toolbar + app->updateActions(); //SRN: To update a Save button in the toolbar } // if ( app ) @@ -403,7 +403,7 @@ void GEOMToolsGUI::OnEditCopy() //===================================================================================== bool GEOMToolsGUI::Import() { - SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( getGeometryGUI()->getApp() ); + SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( getGeometryGUI()->getApp() ); //SUIT_Application* app = getGeometryGUI()->getApp(); if (! app) return false; @@ -448,23 +448,27 @@ bool GEOMToolsGUI::Import() QString fileType; - QString file = getFileName(app->desktop(), "", aMap, tr("GEOM_MEN_IMPORT"), true, fileType ); - if( file.isEmpty() || fileType.isEmpty() ) + QString fileName = getFileName(app->desktop(), "", aMap, + tr("GEOM_MEN_IMPORT"), true, fileType); + if (fileName.isEmpty() || fileType.isEmpty()) return false; - GEOM_Operation* anOp = new GEOM_Operation( app, aInsOp.in() ); + GEOM_Operation* anOp = new GEOM_Operation (app, aInsOp.in()); try { SUIT_OverrideCursor wc; - app->putInfo( tr("GEOM_PRP_LOADING").arg(SUIT_Tools::file( file, /*withExten=*/true )) ); + app->putInfo(tr("GEOM_PRP_LOADING").arg(SUIT_Tools::file(fileName, /*withExten=*/true))); anOp->start(); - anObj = aInsOp->Import( file.latin1(), fileType.latin1() ); + CORBA::String_var fileN = fileName.latin1(); + CORBA::String_var fileT = fileType.latin1(); + anObj = aInsOp->Import(fileN, fileT); if ( !anObj->_is_nil() && aInsOp->IsDone() ) { - anObj->SetName( GEOMBase::GetDefaultName( QObject::tr( "GEOM_IMPORT" ) ).latin1() ); - QString aPublishObjName = GEOMBase::GetDefaultName( SUIT_Tools::file( file, /*withExten=*/true )); + anObj->SetName(GEOMBase::GetDefaultName(QObject::tr("GEOM_IMPORT")).latin1()); + QString aPublishObjName = + GEOMBase::GetDefaultName(SUIT_Tools::file(fileName, /*withExten=*/true)); SALOMEDS::Study_var aDSStudy = GeometryGUI::ClientStudyToStudy(aStudy); GeometryGUI::GetGeomGen()->PublishInStudy(aDSStudy, diff --git a/src/GEOM_I/GEOM_IInsertOperations_i.cc b/src/GEOM_I/GEOM_IInsertOperations_i.cc index 1a525dc29..dccede47a 100644 --- a/src/GEOM_I/GEOM_IInsertOperations_i.cc +++ b/src/GEOM_I/GEOM_IInsertOperations_i.cc @@ -137,32 +137,30 @@ GEOM::GEOM_Object_ptr GEOM_IInsertOperations_i::Import void GEOM_IInsertOperations_i::ImportTranslators (GEOM::string_array_out theFormats, GEOM::string_array_out thePatterns) { - // Get sequences of available formats - Handle(TColStd_HSequenceOfAsciiString) aFormats = new TColStd_HSequenceOfAsciiString; - Handle(TColStd_HSequenceOfAsciiString) aPatterns = new TColStd_HSequenceOfAsciiString; - if (!GetOperations()->ImportTranslators(aFormats, aPatterns) || - aFormats->Length() != aPatterns->Length()) - { - aFormats->Clear(); aPatterns->Clear(); - } - - const int formSize = aFormats->Length(), pattSize = aPatterns->Length(); - // allocate the CORBA arrays GEOM::string_array_var aFormatsArray = new GEOM::string_array(); GEOM::string_array_var aPatternsArray = new GEOM::string_array(); - aFormatsArray->length(formSize); - aPatternsArray->length(formSize); - - // fill the local CORBA arrays with values from sequences - CORBA::Long i = 1; - for (; i <= formSize; i++) { - aFormatsArray[i-1] = CORBA::string_dup(aFormats->Value(i).ToCString()); - aPatternsArray[i-1] = CORBA::string_dup(aPatterns->Value(i).ToCString()); + + // Get sequences of available formats + Handle(TColStd_HSequenceOfAsciiString) aFormats = new TColStd_HSequenceOfAsciiString; + Handle(TColStd_HSequenceOfAsciiString) aPatterns = new TColStd_HSequenceOfAsciiString; + if (GetOperations()->ImportTranslators(aFormats, aPatterns)) { + const int formSize = aFormats->Length(); + if (formSize == aPatterns->Length()) { + aFormatsArray->length(formSize); + aPatternsArray->length(formSize); + + // fill the local CORBA arrays with values from sequences + CORBA::Long i = 1; + for (; i <= formSize; i++) { + aFormatsArray[i-1] = CORBA::string_dup(aFormats->Value(i).ToCString()); + aPatternsArray[i-1] = CORBA::string_dup(aPatterns->Value(i).ToCString()); + } + } } // initialize out-parameters with local arrays - theFormats = aFormatsArray._retn(); + theFormats = aFormatsArray._retn(); thePatterns = aPatternsArray._retn(); } @@ -174,28 +172,29 @@ void GEOM_IInsertOperations_i::ImportTranslators void GEOM_IInsertOperations_i::ExportTranslators (GEOM::string_array_out theFormats, GEOM::string_array_out thePatterns) { - // Get sequences of available formats - Handle(TColStd_HSequenceOfAsciiString) aFormats = new TColStd_HSequenceOfAsciiString; - Handle(TColStd_HSequenceOfAsciiString) aPatterns = new TColStd_HSequenceOfAsciiString; - if (!GetOperations()->ExportTranslators(aFormats, aPatterns)) return; - - const int formSize = aFormats->Length(), pattSize = aPatterns->Length(); - if (formSize != pattSize) return; - // allocate the CORBA arrays GEOM::string_array_var aFormatsArray = new GEOM::string_array(); GEOM::string_array_var aPatternsArray = new GEOM::string_array(); - aFormatsArray->length(formSize); - aPatternsArray->length(formSize); - - // fill the local CORBA arrays with values from sequences - CORBA::Long i = 1; - for (; i <= formSize; i++) { - aFormatsArray[i-1] = CORBA::string_dup(aFormats->Value(i).ToCString()); - aPatternsArray[i-1] = CORBA::string_dup(aPatterns->Value(i).ToCString()); + + // Get sequences of available formats + Handle(TColStd_HSequenceOfAsciiString) aFormats = new TColStd_HSequenceOfAsciiString; + Handle(TColStd_HSequenceOfAsciiString) aPatterns = new TColStd_HSequenceOfAsciiString; + if (GetOperations()->ExportTranslators(aFormats, aPatterns)) { + const int formSize = aFormats->Length(); + if (formSize == aPatterns->Length()) { + aFormatsArray->length(formSize); + aPatternsArray->length(formSize); + + // fill the local CORBA arrays with values from sequences + CORBA::Long i = 1; + for (; i <= formSize; i++) { + aFormatsArray[i-1] = CORBA::string_dup(aFormats->Value(i).ToCString()); + aPatternsArray[i-1] = CORBA::string_dup(aPatterns->Value(i).ToCString()); + } + } } // initialize out-parameters with local arrays - theFormats = aFormatsArray._retn(); + theFormats = aFormatsArray._retn(); thePatterns = aPatternsArray._retn(); }