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;
44 //================================================================================
48 //================================================================================
49 ObjectStates::ObjectStates(TCollection_AsciiString theType)
55 //================================================================================
59 //================================================================================
60 ObjectStates::~ObjectStates()
64 //================================================================================
66 * \brief Add new object state
67 * \param theState - Object state (vector of notebook variable)
69 //================================================================================
70 void ObjectStates::AddState(const TState &theState)
72 _states.push_back(theState);
75 //================================================================================
77 * \brief Return current object state
78 * \\retval state - Object state (vector of notebook variable)
80 //================================================================================
81 TState ObjectStates::GetCurrectState() const
83 return _states[_dumpstate];
87 //================================================================================
91 //================================================================================
92 TAllStates ObjectStates::GetAllStates() const
97 //================================================================================
101 //================================================================================
102 void ObjectStates::IncrementState()
107 //================================================================================
111 //================================================================================
112 TCollection_AsciiString ObjectStates::GetObjectType() const{
116 //================================================================================
120 //================================================================================
121 SMESH_NoteBook::SMESH_NoteBook()
126 //================================================================================
130 //================================================================================
131 SMESH_NoteBook::~SMESH_NoteBook()
133 TVariablesMap::const_iterator it = _objectMap.begin();
134 for(;it!=_objectMap.end();it++) {
140 //================================================================================
142 * \brief Replace parameters of the functions on the Salome NoteBook Variables
143 * \param theString - Input string
144 * \retval TCollection_AsciiString - Convertion result
146 //================================================================================
147 TCollection_AsciiString SMESH_NoteBook::ReplaceVariables(const TCollection_AsciiString& theString) const
149 _pyCommand aCmd( theString, -1);
150 TCollection_AsciiString aMethod = aCmd.GetMethod();
151 TCollection_AsciiString aObject = aCmd.GetObject();
152 TVariablesMap::const_iterator it = _objectMap.find(aObject);
153 if(!aMethod.IsEmpty() && it != _objectMap.end() ) {
154 ObjectStates *aStates = (*it).second;
155 bool modified = false;
157 cout<<"SMESH_NoteBook::ReplaceVariables :Object Type : "<<aStates->GetObjectType()<<endl;
158 if(aStates->GetObjectType().IsEqual("LocalLength")) {
159 if(aMethod == "SetLength") {
160 if(!aStates->GetCurrectState().at(0).IsEmpty() )
161 aCmd.SetArg(1,aStates->GetCurrectState().at(0));
162 aStates->IncrementState();
164 else if(aMethod == "SetPrecision") {
165 if(!aStates->GetCurrectState().at(1).IsEmpty() )
166 aCmd.SetArg(1,aStates->GetCurrectState().at(1));
167 aStates->IncrementState();
170 return aCmd.GetString();
175 //================================================================================
177 * \brief Private method
179 //================================================================================
180 void SMESH_NoteBook::InitObjectMap()
182 SMESH_Gen_i *aGen = SMESH_Gen_i::GetSMESHGen();
186 SALOMEDS::Study_ptr aStudy = aGen->GetCurrentStudy();
187 if(aStudy->_is_nil())
190 SALOMEDS::SObject_var aSO = aStudy->FindComponent(aGen->ComponentDataType());
191 if(CORBA::is_nil(aSO))
194 SALOMEDS::ChildIterator_var Itr = aStudy->NewChildIterator(aSO);
196 for(Itr->InitEx(true); Itr->More(); Itr->Next()) {
197 SALOMEDS::SObject_var aSObject = Itr->Value();
198 SALOMEDS::GenericAttribute_var anAttr;
199 if ( aSObject->FindAttribute(anAttr, "AttributeString")) {
200 aParameters = SALOMEDS::AttributeString::_narrow(anAttr)->Value();
201 SALOMEDS::ListOfListOfStrings_var aSections = aStudy->ParseVariables(aParameters);
203 cout<<"Entry : "<< aSObject->GetID()<<endl;
204 cout<<"aParameters : "<<aParameters<<endl;
206 TCollection_AsciiString anObjType;
207 CORBA::Object_var anObject = SMESH_Gen_i::SObjectToObject(aSObject);
208 SMESH::SMESH_Hypothesis_var aHyp = SMESH::SMESH_Hypothesis::_narrow(anObject);
209 if(!aHyp->_is_nil()) {
210 anObjType = TCollection_AsciiString(aHyp->GetName());
212 else if(SMESH::SMESH_Mesh_var aMesh = SMESH::SMESH_Mesh::_narrow(anObject)) {
213 anObjType = TCollection_AsciiString("Mesh");
216 cout<<"The object Type : "<<anObjType<<endl;
218 ObjectStates *aState = new ObjectStates(anObjType);
219 for(int i = 0; i < aSections->length(); i++) {
221 SALOMEDS::ListOfStrings aListOfVars = aSections[i];
222 for(int j = 0;j<aListOfVars.length();j++) {
223 TCollection_AsciiString aVar(aListOfVars[j].in());
224 if(!aVar.IsEmpty() && aStudy->IsVariable(aVar.ToCString())) {
225 aVar.InsertBefore(1,"\"");
226 aVar.InsertAfter(aVar.Length(),"\"");
228 aVars.push_back(aVar);
230 cout<<"Variable: '"<<aVar<<"'"<<endl;
233 aState->AddState(aVars);
235 _objectMap.insert(pair<TCollection_AsciiString,ObjectStates*>(TCollection_AsciiString(aSObject->GetID()),aState));