1 // Copyright (C) 2010-2014 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 // File : PV_Tools.cxx
20 // Author : Alexey PETROV
24 #include "PARAVIS_Gen_i.hh"
26 #include <omnithread.h>
27 #include CORBA_SERVER_HEADER(SALOME_Session)
28 #include CORBA_SERVER_HEADER(SALOME_ModuleCatalog)
30 #include <SALOME_NamingService.hxx>
36 //----------------------------------------------------------------------------
37 SALOMEDS::ListOfFileNames* GetListOfFileNames(const QStringList& theFileNames)
39 SALOMEDS::ListOfFileNames_var aListOfFileNames = new SALOMEDS::ListOfFileNames;
40 if(!theFileNames.isEmpty()){
41 aListOfFileNames->length(theFileNames.size());
43 foreach (QString aName, theFileNames) {
44 aListOfFileNames[i] = qPrintable(aName);
48 return aListOfFileNames._retn();
51 //----------------------------------------------------------------------------
52 SALOMEDS::SComponent_var FindOrCreateParaVisComponent(SALOMEDS::Study_ptr theStudyDocument)
54 SALOMEDS::SComponent_var aSComponent = theStudyDocument->FindComponent("PARAVIS");
55 if (aSComponent->_is_nil()) {
56 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudyDocument->NewBuilder();
57 aStudyBuilder->NewCommand();
58 int aLocked = theStudyDocument->GetProperties()->IsLocked();
59 if (aLocked) theStudyDocument->GetProperties()->SetLocked(false);
60 aSComponent = aStudyBuilder->NewComponent("PARAVIS");
61 SALOMEDS::GenericAttribute_var anAttr =
62 aStudyBuilder->FindOrCreateAttribute(aSComponent, "AttributeName");
63 SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(anAttr);
65 CORBA::ORB_var anORB = PARAVIS_Gen_i::GetORB();
66 SALOME_NamingService *NamingService = new SALOME_NamingService( anORB );
67 CORBA::Object_var objVarN = NamingService->Resolve("/Kernel/ModulCatalog");
68 SALOME_ModuleCatalog::ModuleCatalog_var Catalogue =
69 SALOME_ModuleCatalog::ModuleCatalog::_narrow(objVarN);
70 SALOME_ModuleCatalog::Acomponent_var Comp = Catalogue->GetComponent( "PARAVIS" );
71 if ( !CORBA::is_nil(Comp) ) {
72 aName->SetValue( Comp->componentusername() );
75 anAttr = aStudyBuilder->FindOrCreateAttribute(aSComponent, "AttributePixMap");
76 SALOMEDS::AttributePixMap_var aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
77 aPixmap->SetPixMap( "pqAppIcon16.png" );
79 // Create Attribute parameters for future using
80 anAttr = aStudyBuilder->FindOrCreateAttribute(aSComponent, "AttributeParameter");
82 PARAVIS_Gen_var aParaVisGen = PARAVIS_Gen_i::GetParavisGenImpl()->_this();
83 aStudyBuilder->DefineComponentInstance(aSComponent, aParaVisGen);
85 theStudyDocument->GetProperties()->SetLocked(true);
86 aStudyBuilder->CommitCommand();
91 PARAVIS_Base_i* GET_SERVANT(CORBA::Object_ptr aObj) {
92 //dynamic_cast<PARAVIS_Base_i*>(PARAVIS_Gen_i::GetPOA()->reference_to_servant(OBJ).in())
93 if (CORBA::is_nil(aObj))
96 PortableServer::POA_ptr aPOA = PARAVIS_Gen_i::GetPOA();
97 PortableServer::ServantBase_var aServant = aPOA->reference_to_servant(aObj);
98 return dynamic_cast<PARAVIS_Base_i*>(aServant.in());
100 MESSAGE("GET_SERVANT: Unknown exception!!!");
105 void SetRestoreParam(SALOMEDS::SComponent_ptr theComponent, bool theRestore)
107 SALOMEDS::GenericAttribute_var anAttr;
108 if (theComponent->FindAttribute(anAttr, "AttributeParameter")) {
109 SALOMEDS::AttributeParameter_var aParams = SALOMEDS::AttributeParameter::_narrow(anAttr);
110 aParams->SetBool("RestorePath", theRestore);
114 bool GetRestoreParam(SALOMEDS::SComponent_ptr theComponent)
116 SALOMEDS::GenericAttribute_var anAttr;
117 if (theComponent->FindAttribute(anAttr, "AttributeParameter")) {
118 SALOMEDS::AttributeParameter_var aParams = SALOMEDS::AttributeParameter::_narrow(anAttr);
119 if (aParams->IsSet("RestorePath", 2)) {
120 return aParams->GetBool("RestorePath");