Back to index

salome-paravis  6.5.0
PV_Tools.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2010-2012  CEA/DEN, EDF R&D
00002 //
00003 // This library is free software; you can redistribute it and/or
00004 // modify it under the terms of the GNU Lesser General Public
00005 // License as published by the Free Software Foundation; either
00006 // version 2.1 of the License.
00007 //
00008 // This library is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011 // Lesser General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU Lesser General Public
00014 // License along with this library; if not, write to the Free Software
00015 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00016 //
00017 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00018 //
00019 //  File   : PV_Tools.cxx
00020 //  Author : Alexey PETROV
00021 //  Module : VISU
00022 //
00023 #include "PV_Tools.h"  
00024 #include "PARAVIS_Gen_i.hh"
00025 
00026 #include <omnithread.h>
00027 #include CORBA_SERVER_HEADER(SALOME_Session)
00028 #include CORBA_SERVER_HEADER(SALOME_ModuleCatalog)
00029 
00030 #include <SALOME_NamingService.hxx>
00031 
00032 #include <QString>
00033 
00034 namespace PARAVIS
00035 {
00036 //----------------------------------------------------------------------------
00037   SALOMEDS::ListOfFileNames* GetListOfFileNames(const QStringList& theFileNames)
00038   {
00039     SALOMEDS::ListOfFileNames_var aListOfFileNames = new SALOMEDS::ListOfFileNames;
00040     if(!theFileNames.isEmpty()){
00041       aListOfFileNames->length(theFileNames.size());
00042       int i = 0;
00043       foreach (QString aName, theFileNames) {
00044         aListOfFileNames[i] = qPrintable(aName);
00045         i++;
00046       }
00047     }
00048     return aListOfFileNames._retn();
00049   }
00050 
00051   //----------------------------------------------------------------------------
00052   SALOMEDS::SComponent_var FindOrCreateParaVisComponent(SALOMEDS::Study_ptr theStudyDocument)
00053   {
00054     SALOMEDS::SComponent_var aSComponent = theStudyDocument->FindComponent("PARAVIS");
00055     if (aSComponent->_is_nil()) {
00056       SALOMEDS::StudyBuilder_var aStudyBuilder = theStudyDocument->NewBuilder();
00057       aStudyBuilder->NewCommand();
00058       int aLocked = theStudyDocument->GetProperties()->IsLocked();
00059       if (aLocked) theStudyDocument->GetProperties()->SetLocked(false);
00060       aSComponent = aStudyBuilder->NewComponent("PARAVIS");
00061       SALOMEDS::GenericAttribute_var anAttr = 
00062         aStudyBuilder->FindOrCreateAttribute(aSComponent, "AttributeName");
00063       SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(anAttr);
00064       
00065       CORBA::ORB_var anORB = PARAVIS_Gen_i::GetORB();
00066       SALOME_NamingService *NamingService = new SALOME_NamingService( anORB );
00067       CORBA::Object_var objVarN = NamingService->Resolve("/Kernel/ModulCatalog");
00068       SALOME_ModuleCatalog::ModuleCatalog_var Catalogue  = 
00069         SALOME_ModuleCatalog::ModuleCatalog::_narrow(objVarN);
00070       SALOME_ModuleCatalog::Acomponent_var Comp = Catalogue->GetComponent( "PARAVIS" );
00071       if ( !CORBA::is_nil(Comp) ) {
00072         aName->SetValue( Comp->componentusername() );
00073       }
00074       
00075       anAttr = aStudyBuilder->FindOrCreateAttribute(aSComponent, "AttributePixMap");
00076       SALOMEDS::AttributePixMap_var aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
00077       aPixmap->SetPixMap( "pqAppIcon16.png" );
00078 
00079       // Create Attribute parameters for future using
00080       anAttr = aStudyBuilder->FindOrCreateAttribute(aSComponent, "AttributeParameter");
00081       
00082       PARAVIS_Gen_var aParaVisGen = PARAVIS_Gen_i::GetParavisGenImpl()->_this();
00083       aStudyBuilder->DefineComponentInstance(aSComponent, aParaVisGen);
00084       if (aLocked) 
00085         theStudyDocument->GetProperties()->SetLocked(true);
00086       aStudyBuilder->CommitCommand();
00087     }
00088     return aSComponent;
00089   }
00090 
00091   PARAVIS_Base_i* GET_SERVANT(CORBA::Object_ptr aObj) {
00092     //dynamic_cast<PARAVIS_Base_i*>(PARAVIS_Gen_i::GetPOA()->reference_to_servant(OBJ).in())
00093     if (CORBA::is_nil(aObj))
00094       return NULL;
00095     try {
00096       PortableServer::POA_ptr aPOA = PARAVIS_Gen_i::GetPOA();
00097       PortableServer::ServantBase_var aServant = aPOA->reference_to_servant(aObj);
00098       return dynamic_cast<PARAVIS_Base_i*>(aServant.in());
00099     } catch (...) {
00100       MESSAGE("GET_SERVANT: Unknown exception!!!");
00101     }
00102     return NULL;
00103   }
00104 
00105   void SetRestoreParam(SALOMEDS::SComponent_ptr theComponent, bool theRestore)
00106   {
00107     SALOMEDS::GenericAttribute_var anAttr;
00108     if (theComponent->FindAttribute(anAttr, "AttributeParameter")) {
00109       SALOMEDS::AttributeParameter_var aParams = SALOMEDS::AttributeParameter::_narrow(anAttr);
00110       aParams->SetBool("RestorePath", theRestore);
00111     }
00112   }
00113 
00114   bool GetRestoreParam(SALOMEDS::SComponent_ptr theComponent)
00115   {
00116     SALOMEDS::GenericAttribute_var anAttr;
00117     if (theComponent->FindAttribute(anAttr, "AttributeParameter")) {
00118       SALOMEDS::AttributeParameter_var aParams = SALOMEDS::AttributeParameter::_narrow(anAttr);
00119       if (aParams->IsSet("RestorePath", 2)) {
00120         return aParams->GetBool("RestorePath");
00121       }
00122     }
00123     return true;
00124   }
00125 };