1 // Copyright (C) 2008 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License.
9 // This library is distributed in the hope that it will be useful
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 // File : SMESH_NoteBook.cxx
21 // Author : Roman NIKOLAEV
23 #include "SMESH_2smeshpy.hxx"
24 #include "SMESH_NoteBook.hxx"
25 #include "SMESH_Gen_i.hxx"
27 #include <Resource_DataMapOfAsciiStringAsciiString.hxx>
28 #include <TColStd_SequenceOfAsciiString.hxx>
29 #include <TColStd_HSequenceOfInteger.hxx>
35 static int MYDEBUG = 0;
37 static int MYDEBUG = 0;
42 //================================================================================
46 //================================================================================
47 SMESH_NoteBook::SMESH_NoteBook()
52 //================================================================================
56 //================================================================================
57 SMESH_NoteBook::~SMESH_NoteBook()
61 //================================================================================
63 * \brief Replace parameters of the functions on the Salome NoteBook Variables
64 * \param theString - Input string
65 * \retval TCollection_AsciiString - Convertion result
67 //================================================================================
68 TCollection_AsciiString SMESH_NoteBook::ReplaceVariables(const TCollection_AsciiString& theString) const
70 _pyCommand aCmd( theString, -1);
71 TCollection_AsciiString aMethod = aCmd.GetMethod();
72 TCollection_AsciiString aObject = aCmd.GetObject();
73 TVariablesMap::const_iterator it = _objectMap.find(aObject);
74 if(!aMethod.IsEmpty() && it != _objectMap.end() ) {
76 if(aMethod == "SetLength" && !(*it).second.at(0).IsEmpty() ) {
77 aCmd.SetArg(1,(*it).second.at(0));
79 else if(aMethod == "SetPrecision" && !(*it).second.at(1).IsEmpty() ){
80 aCmd.SetArg(1,(*it).second.at(1));
82 return aCmd.GetString();
87 //================================================================================
89 * \brief Private method
91 //================================================================================
92 void SMESH_NoteBook::InitObjectMap()
94 SMESH_Gen_i *aGen = SMESH_Gen_i::GetSMESHGen();
98 SALOMEDS::Study_ptr aStudy = aGen->GetCurrentStudy();
102 SALOMEDS::SObject_var aSO = aStudy->FindComponent(aGen->ComponentDataType());
103 if(CORBA::is_nil(aSO))
106 SALOMEDS::ChildIterator_var Itr = aStudy->NewChildIterator(aSO);
107 TCollection_AsciiString aParameters;
108 for(Itr->InitEx(true); Itr->More(); Itr->Next()) {
109 SALOMEDS::SObject_var aSObject = Itr->Value();
110 SALOMEDS::GenericAttribute_var anAttr;
111 if ( aSObject->FindAttribute(anAttr, "AttributeString")) {
112 aParameters = TCollection_AsciiString(SALOMEDS::AttributeString::_narrow(anAttr)->Value());
113 vector<string> vect = ParseVariables(aParameters.ToCString(),':');
115 cout<<"Entry : "<< aSObject->GetID()<<endl;
116 cout<<"aParameters : "<<aParameters<<endl;
118 vector<TCollection_AsciiString> aVars;
119 for(int i = 0;i<vect.size();i++) {
120 TCollection_AsciiString aVar(vect[i].c_str());
121 if(!aVar.IsEmpty() && aStudy->IsVariable(vect[i].c_str())) {
122 aVar.InsertBefore(1,"\"");
123 aVar.InsertAfter(aVar.Length(),"\"");
125 aVars.push_back(aVar);
127 cout<<"Variable: "<<aVar<<endl;
130 _objectMap.insert(pair<TCollection_AsciiString,vector<TCollection_AsciiString> >(TCollection_AsciiString(aSObject->GetID()),aVars));
135 //================================================================================
137 * \brief Private method
139 //================================================================================
140 vector<string> SMESH_NoteBook::ParseVariables(const string& theVariables, const char sep) const
142 vector<string> aResult;
143 if(theVariables[0] == sep ) aResult.push_back(string());
144 int pos = theVariables.find(sep);
146 aResult.push_back(theVariables);
150 string s = theVariables;
151 if(s[0] == sep) s = s.substr(1, s.size());
152 while((pos = s.find(sep)) >= 0) {
153 aResult.push_back(s.substr(0, pos));
154 s = s.substr(pos+1, s.size());
157 if(!s.empty() && s[0] != sep) aResult.push_back(s);
158 if(theVariables[theVariables.size()-1] == sep) aResult.push_back(string());