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"
26 #include "SMESH_PythonDump.hxx"
28 #include <Resource_DataMapOfAsciiStringAsciiString.hxx>
29 #include <TColStd_SequenceOfAsciiString.hxx>
30 #include <TColStd_HSequenceOfInteger.hxx>
36 static int MYDEBUG = 0;
38 static int MYDEBUG = 0;
44 void SetVariable(Handle(_pyCommand) theCommand,const ObjectStates* theStates, int position, int theArgNb);
46 //================================================================================
50 //================================================================================
51 ObjectStates::ObjectStates(TCollection_AsciiString theType)
57 //================================================================================
61 //================================================================================
62 ObjectStates::~ObjectStates()
66 //================================================================================
68 * \brief Add new object state
69 * \param theState - Object state (vector of notebook variable)
71 //================================================================================
72 void ObjectStates::AddState(const TState &theState)
74 _states.push_back(theState);
77 //================================================================================
79 * \brief Return current object state
80 * \\retval state - Object state (vector of notebook variable)
82 //================================================================================
83 TState ObjectStates::GetCurrectState() const
85 if(_states.size() > _dumpstate)
86 return _states[_dumpstate];
92 //================================================================================
96 //================================================================================
97 TAllStates ObjectStates::GetAllStates() const
102 //================================================================================
106 //================================================================================
107 void ObjectStates::IncrementState()
112 //================================================================================
116 //================================================================================
117 TCollection_AsciiString ObjectStates::GetObjectType() const{
122 //================================================================================
126 //================================================================================
127 LayerDistributionStates::LayerDistributionStates():
128 ObjectStates("LayerDistribution")
131 //================================================================================
135 //================================================================================
136 LayerDistributionStates::~LayerDistributionStates()
141 //================================================================================
143 * \brief AddDistribution
145 //================================================================================
146 void LayerDistributionStates::AddDistribution(const TCollection_AsciiString& theDistribution)
148 _distributions.insert(pair<TCollection_AsciiString,TCollection_AsciiString>(theDistribution,""));
151 //================================================================================
153 * \brief HasDistribution
155 //================================================================================
156 bool LayerDistributionStates::HasDistribution(const TCollection_AsciiString& theDistribution) const
158 return _distributions.find(theDistribution) != _distributions.end();
161 //================================================================================
163 * \brief SetDistributionType
165 //================================================================================
166 bool LayerDistributionStates::SetDistributionType(const TCollection_AsciiString& theDistribution,
167 const TCollection_AsciiString& theType)
169 TDistributionMap::iterator it = _distributions.find(theDistribution);
170 if(it == _distributions.end())
172 (*it).second = theType;
176 //================================================================================
178 * \brief GetDistributionType
180 //================================================================================
181 TCollection_AsciiString LayerDistributionStates::
182 GetDistributionType(const TCollection_AsciiString& theDistribution) const
184 TDistributionMap::const_iterator it = _distributions.find(theDistribution);
185 return (it == _distributions.end()) ? TCollection_AsciiString() : (*it).second;
188 //================================================================================
192 //================================================================================
193 SMESH_NoteBook::SMESH_NoteBook()
198 //================================================================================
202 //================================================================================
203 SMESH_NoteBook::~SMESH_NoteBook()
205 TVariablesMap::const_iterator it = _objectMap.begin();
206 for(;it!=_objectMap.end();it++) {
212 //================================================================================
214 * \brief Replace parameters of the functions on the Salome NoteBook Variables
215 * \param theString - Input string
216 * \retval TCollection_AsciiString - Convertion result
218 //================================================================================
219 void SMESH_NoteBook::ReplaceVariables()
221 for(int i=0;i<_commands.size();i++) {
222 Handle(_pyCommand) aCmd = _commands[i];
223 TCollection_AsciiString aMethod = aCmd->GetMethod();
224 TCollection_AsciiString aObject = aCmd->GetObject();
225 TCollection_AsciiString aResultValue = aCmd->GetResultValue();
227 cout<<"Command before : "<< aCmd->GetString()<<endl;
228 cout<<"Method : "<< aMethod<<endl;
229 cout<<"Object : "<< aObject<<endl;
230 cout<<"Result : "<< aResultValue<<endl;
233 // check if method modifies the object itself
234 TVariablesMap::const_iterator it = _objectMap.find(aObject);
235 if(it == _objectMap.end()) // check if method returns a new object
236 it = _objectMap.find(aResultValue);
238 if(it == _objectMap.end()) { // check if method modifies a mesh using mesh editor
239 TMeshEditorMap::const_iterator meIt = myMeshEditors.find(aObject);
240 if(meIt != myMeshEditors.end()) {
241 TCollection_AsciiString aMesh = (*meIt).second;
242 it = _objectMap.find(aMesh);
246 if(it == _objectMap.end()) { // additional check for pattern mapping
247 if(aMethod.IsEqual("ApplyToMeshFaces") ||
248 aMethod.IsEqual("ApplyToHexahedrons"))
249 it = _objectMap.find(aCmd->GetArg(1));
252 if(it != _objectMap.end()) {
254 cout << "Found object : " << (*it).first << endl;
255 ObjectStates *aStates = (*it).second;
256 // Case for LocalLength hypothesis
257 if(aStates->GetObjectType().IsEqual("LocalLength") && aStates->GetCurrectState().size() >= 2) {
258 if(aMethod.IsEqual("SetLength")) {
259 if(!aStates->GetCurrectState().at(0).IsEmpty() )
260 aCmd->SetArg(1,aStates->GetCurrectState().at(0));
261 aStates->IncrementState();
263 else if(aMethod.IsEqual("SetPrecision")) {
264 if(!aStates->GetCurrectState().at(1).IsEmpty() )
265 aCmd->SetArg(1,aStates->GetCurrectState().at(1));
266 aStates->IncrementState();
270 // Case for SegmentLengthAroundVertex hypothesis
271 else if(aStates->GetObjectType().IsEqual("SegmentLengthAroundVertex")
272 && aStates->GetCurrectState().size() >= 1) {
273 if(aMethod == "SetLength") {
274 if(!aStates->GetCurrectState().at(0).IsEmpty() )
275 aCmd->SetArg(1,aStates->GetCurrectState().at(0));
276 aStates->IncrementState();
280 // Case for Arithmetic1D and StartEndLength hypothesis
281 else if(aStates->GetObjectType().IsEqual("Arithmetic1D") ||
282 aStates->GetObjectType().IsEqual("StartEndLength")) {
283 if(aMethod == "SetLength" &&
284 aStates->GetCurrectState().size() >= 2) {
285 if(aCmd->GetArg(2) == "1" && !aStates->GetCurrectState().at(0).IsEmpty())
286 aCmd->SetArg(1,aStates->GetCurrectState().at(0));
287 else if(!aStates->GetCurrectState().at(1).IsEmpty())
288 aCmd->SetArg(1,aStates->GetCurrectState().at(1));
289 aStates->IncrementState();
293 //Case for Deflection1D hypothesis
294 else if(aStates->GetObjectType().IsEqual("Deflection1D")){
295 if(aMethod == "SetDeflection" && aStates->GetCurrectState().size() >= 1) {
296 if(!aStates->GetCurrectState().at(0).IsEmpty() )
297 aCmd->SetArg(1,aStates->GetCurrectState().at(0));
298 aStates->IncrementState();
302 // Case for LayerDistribution hypothesis (not finished yet)
303 else if(aStates->GetObjectType() == "LayerDistribution") {
304 if(aMethod == "SetLayerDistribution"){
305 LayerDistributionStates* aLDStates = (LayerDistributionStates*)(aStates);
306 aLDStates->AddDistribution(aCmd->GetArg(1));
308 cout<<"Add Distribution :"<<aCmd->GetArg(1)<<endl;
312 // Case for MaxElementArea hypothesis
313 else if(aStates->GetObjectType().IsEqual("MaxElementArea")){
314 if(aMethod == "SetMaxElementArea" && aStates->GetCurrectState().size() >= 1) {
315 if(!aStates->GetCurrectState().at(0).IsEmpty() )
316 aCmd->SetArg(1,aStates->GetCurrectState().at(0));
317 aStates->IncrementState();
321 // Case for MaxElementVolume hypothesis
322 else if(aStates->GetObjectType().IsEqual("MaxElementVolume")){
323 if(aMethod == "SetMaxElementVolume" && aStates->GetCurrectState().size() >= 1) {
324 if(!aStates->GetCurrectState().at(0).IsEmpty() )
325 aCmd->SetArg(1,aStates->GetCurrectState().at(0));
326 aStates->IncrementState();
330 // Case for NETGEN_Parameters_2D or NETGEN_Parameters_2D hypothesis
331 else if(aStates->GetObjectType().IsEqual("NETGEN_Parameters_2D") ||
332 aStates->GetObjectType().IsEqual("NETGEN_Parameters")){
333 if(aMethod == "SetMaxSize" && aStates->GetCurrectState().size() >= 1) {
334 if(!aStates->GetCurrectState().at(0).IsEmpty() )
335 aCmd->SetArg(1,aStates->GetCurrectState().at(0));
336 aStates->IncrementState();
338 else if(aMethod == "SetGrowthRate" && aStates->GetCurrectState().size() >= 2) {
339 if(!aStates->GetCurrectState().at(1).IsEmpty() )
340 aCmd->SetArg(1,aStates->GetCurrectState().at(1));
341 aStates->IncrementState();
343 else if(aMethod == "SetNbSegPerEdge" && aStates->GetCurrectState().size() >= 3) {
344 if(!aStates->GetCurrectState().at(2).IsEmpty() )
345 aCmd->SetArg(1,aStates->GetCurrectState().at(2));
346 aStates->IncrementState();
348 else if(aMethod == "SetNbSegPerRadius" && aStates->GetCurrectState().size() >= 4) {
349 if(!aStates->GetCurrectState().at(3).IsEmpty() )
350 aCmd->SetArg(1,aStates->GetCurrectState().at(3));
351 aStates->IncrementState();
355 // Case for NETGEN_SimpleParameters_3D or NETGEN_SimpleParameters_2D hypothesis
356 else if(aStates->GetObjectType().IsEqual("NETGEN_SimpleParameters_3D") ||
357 aStates->GetObjectType().IsEqual("NETGEN_SimpleParameters_2D")){
359 if((aMethod == "SetNumberOfSegments" || aMethod == "SetLocalLength") &&
360 aStates->GetCurrectState().size() >= 1) {
361 if(!aStates->GetCurrectState().at(0).IsEmpty() )
362 aCmd->SetArg(1,aStates->GetCurrectState().at(0));
363 aStates->IncrementState();
365 else if(aMethod == "SetMaxElementArea" && aStates->GetCurrectState().size() >= 2) {
366 if(!aStates->GetCurrectState().at(1).IsEmpty() )
367 aCmd->SetArg(1,aStates->GetCurrectState().at(1));
368 aStates->IncrementState();
370 else if(aMethod == "SetMaxElementVolume" && aStates->GetCurrectState().size() >= 3) {
371 if(!aStates->GetCurrectState().at(2).IsEmpty() )
372 aCmd->SetArg(1,aStates->GetCurrectState().at(2));
373 aStates->IncrementState();
375 else if(aMethod == "LengthFromEdges" || aMethod == "LengthFromFaces"){
376 aStates->IncrementState();
380 // Case for NumberOfLayers hypothesis
381 else if(aStates->GetObjectType().IsEqual("NumberOfLayers")){
382 if(aMethod == "SetNumberOfLayers" && aStates->GetCurrectState().size() >= 1) {
383 if(!aStates->GetCurrectState().at(0).IsEmpty() )
384 aCmd->SetArg(1,aStates->GetCurrectState().at(0));
385 aStates->IncrementState();
389 // Case for NumberOfSegments hypothesis
390 else if(aStates->GetObjectType().IsEqual("NumberOfSegments")){
391 if(aMethod == "SetNumberOfSegments" && aStates->GetCurrectState().size() >= 1) {
392 if(!aStates->GetCurrectState().at(0).IsEmpty() )
393 aCmd->SetArg(1,aStates->GetCurrectState().at(0));
394 if(aStates->GetCurrectState().size()==1)
395 aStates->IncrementState();
397 else if (aMethod == "SetScaleFactor" && aStates->GetCurrectState().size() >= 2) {
398 if(!aStates->GetCurrectState().at(1).IsEmpty() )
399 aCmd->SetArg(1,aStates->GetCurrectState().at(1));
400 aStates->IncrementState();
404 else if(aStates->GetObjectType().IsEqual("Mesh")) {
405 TState aCurrentState = aStates->GetCurrectState();
406 int aCurrentStateSize = aCurrentState.size();
407 if(aMethod.IsEqual("Translate") ||
408 aMethod.IsEqual("TranslateMakeGroups") ||
409 aMethod.IsEqual("TranslateMakeMesh")) {
410 bool isVariableFound = false;
412 for(int i = 1, n = aCmd->GetNbArgs(); i <= n; i++) {
413 if(aCmd->GetArg(i).IsEqual("SMESH.PointStruct")) {
419 if(aCurrentStateSize == 3) { // translation by dx, dy, dz
420 for(int j = 0; j < aCurrentStateSize; j++) {
421 if(!aCurrentState.at(j).IsEmpty()) {
422 isVariableFound = true;
423 aCmd->SetArg(anArgIndex+j, aCurrentState.at(j));
427 else if(aCurrentStateSize == 6) { // translation by x1, x2, y1, y2, z1, z2
428 // TODO: limitation until operations on the variables will be introduced
430 isVariableFound = true;
431 for(int j = 0; j < 3; j++) {
432 TCollection_AsciiString anArg = aCmd->GetArg(anArgIndex+j);
433 TCollection_AsciiString aValue1 = aCurrentState.at(2*j), aValue2 = aCurrentState.at(2*j+1);
434 bool aV1 = !aValue1.IsEmpty();
435 bool aV2 = !aValue2.IsEmpty();
436 double aValue, aCurrentValue = anArg.IsRealValue() ? anArg.RealValue() : 0;
438 if(!GetReal(aValue1, aValue))
440 aValue2 = TCollection_AsciiString( aValue + aCurrentValue );
442 else if(!aV1 && aV2) {
443 if(!GetReal(aValue2, aValue))
445 aValue1 = TCollection_AsciiString( aValue - aCurrentValue );
447 else if(!aV1 && !aV2) {
448 aValue1 = TCollection_AsciiString( 0 );
449 aValue2 = TCollection_AsciiString( aCurrentValue );
451 aCmd->SetArg(anArgIndex+j, aValue1 + ", " + aValue2 );
456 if(isVariableFound) {
457 TCollection_AsciiString aDim;
458 if(aCurrentStateSize == 6)
460 aCmd->SetArg(anArgIndex - 1, TCollection_AsciiString(SMESH_2smeshpy::SmeshpyName())+".PointStructStr"+aDim);
461 aCmd->SetArg(anArgIndex - 2, TCollection_AsciiString(SMESH_2smeshpy::SmeshpyName())+".DirStructStr");
463 aStates->IncrementState();
465 else if(aMethod.IsEqual("Rotate") ||
466 aMethod.IsEqual("RotateMakeGroups") ||
467 aMethod.IsEqual("RotateMakeMesh") ||
468 aMethod.IsEqual("RotationSweep") ||
469 aMethod.IsEqual("RotationSweepMakeGroups") ||
470 aMethod.IsEqual("Mirror") ||
471 aMethod.IsEqual("MirrorMakeMesh") ||
472 aMethod.IsEqual("MirrorMakeGroups") ||
473 aMethod.IsEqual("MirrorObject") ||
474 aMethod.IsEqual("MirrorObjectMakeMesh") ||
475 aMethod.IsEqual("MirrorObjectMakeGroups")) {
476 bool isSubstitute = false;
478 for(int i = 1, n = aCmd->GetNbArgs(); i <= n; i++) {
479 if(aCmd->GetArg(i).IsEqual("SMESH.AxisStruct")) {
485 for(int j = 0; j < aCurrentStateSize; j++) {
486 if(!aCurrentState.at(j).IsEmpty()) {
487 if(j < 6) // 0-5 - axis struct, 6 - angle (rotation & sweep), 7-8 - nbSteps and tolerance (sweep)
489 aCmd->SetArg(anArgIndex+j, aCurrentState.at(j));
494 aCmd->SetArg(anArgIndex - 1, TCollection_AsciiString(SMESH_2smeshpy::SmeshpyName())+".AxisStructStr");
495 aStates->IncrementState();
497 else if(aMethod.IsEqual("AddNode") ||
498 aMethod.IsEqual("MoveClosestNodeToPoint")) {
499 for(int j = 0; j < aCurrentStateSize; j++) {
500 if(!aCurrentState.at(j).IsEmpty())
501 aCmd->SetArg(j+1, aCurrentState.at(j));
503 aStates->IncrementState();
505 else if(aMethod.IsEqual("MoveNode")) {
506 for(int j = 0; j < aCurrentStateSize; j++) {
507 if(!aCurrentState.at(j).IsEmpty())
508 aCmd->SetArg(j+2, aCurrentState.at(j));
510 aStates->IncrementState();
512 else if(aMethod.IsEqual("ExtrusionSweep") ||
513 aMethod.IsEqual("ExtrusionSweepMakeGroups")) {
514 bool isSubstitute = false;
516 for(int i = 1, n = aCmd->GetNbArgs(); i <= n; i++) {
517 if(aCmd->GetArg(i).IsEqual("SMESH.PointStruct")) {
523 for(int j = 0; j < aCurrentStateSize; j++) {
524 if(!aCurrentState.at(j).IsEmpty()) {
525 if(j < 3) // 0-2 - dir struct, 3 - number of steps
527 aCmd->SetArg(anArgIndex+j, aCurrentState.at(j));
532 aCmd->SetArg(anArgIndex - 1, TCollection_AsciiString(SMESH_2smeshpy::SmeshpyName())+".PointStructStr");
533 aCmd->SetArg(anArgIndex - 2, TCollection_AsciiString(SMESH_2smeshpy::SmeshpyName())+".DirStructStr");
535 aStates->IncrementState();
537 else if(aMethod.IsEqual("ExtrusionAlongPath") ||
538 aMethod.IsEqual("ExtrusionAlongPathMakeGroups") ||
539 /* workaround for a bug in the command parsing algorithm */
540 aCmd->GetString().Search("ExtrusionAlongPathMakeGroups") != -1) {
541 int aNbAngles = aCurrentStateSize-3; // State looks like "Angle1:...:AngleN:X:Y:Z"
542 bool isSubstitute = false;
544 for(int i = 1, n = aCmd->GetNbArgs(); i <= n; i++) {
545 if(aCmd->GetArg(i).IsEqual("SMESH.PointStruct")) {
546 anArgIndex = i-1-aNbAngles;
552 for(; j < aNbAngles; j++) {
553 if(!aCurrentState.at(j).IsEmpty()) {
554 aCmd->SetArg(anArgIndex+j-1, aCurrentState.at(j));
557 for(; j < aNbAngles+3; j++) {
558 if(!aCurrentState.at(j).IsEmpty()) {
560 aCmd->SetArg(anArgIndex+j+2, aCurrentState.at(j));
565 aCmd->SetArg(anArgIndex + aNbAngles + 1,
566 TCollection_AsciiString(SMESH_2smeshpy::SmeshpyName())+".PointStructStr");
567 aStates->IncrementState();
569 else if(aMethod.IsEqual("TriToQuad") ||
570 aMethod.IsEqual("Concatenate") ||
571 aMethod.IsEqual("ConcatenateWithGroups")) {
572 if(aCurrentStateSize && !aCurrentState.at(0).IsEmpty())
573 aCmd->SetArg(aCmd->GetNbArgs(), aCurrentState.at(0));
574 aStates->IncrementState();
576 else if(aMethod.IsEqual("Smooth") ||
577 aMethod.IsEqual("SmoothParametric")) {
578 int anArgIndex = aCmd->GetNbArgs() - 2;
579 for(int j = 0; j < aCurrentStateSize; j++) {
580 if(!aCurrentState.at(j).IsEmpty())
581 aCmd->SetArg(anArgIndex+j, aCurrentState.at(j));
583 aStates->IncrementState();
585 else if(aMethod.IsEqual("ApplyToMeshFaces") ||
586 aMethod.IsEqual("ApplyToHexahedrons")) {
587 int anArgIndex = aCmd->GetNbArgs()-1;
588 for(int j = 0; j < aCurrentStateSize; j++)
589 if(!aCurrentState.at(j).IsEmpty())
590 aCmd->SetArg(anArgIndex+j, aCurrentState.at(j));
591 aStates->IncrementState();
597 cout << "Object not found" << endl;
600 cout<<"Command after: "<< aCmd->GetString()<<endl;
604 ProcessLayerDistribution();
606 //================================================================================
608 * \brief Private method
610 //================================================================================
611 void SMESH_NoteBook::InitObjectMap()
613 SMESH_Gen_i *aGen = SMESH_Gen_i::GetSMESHGen();
617 SALOMEDS::Study_ptr aStudy = aGen->GetCurrentStudy();
618 if(aStudy->_is_nil())
621 SALOMEDS::SObject_var aSO = aStudy->FindComponent(aGen->ComponentDataType());
622 if(CORBA::is_nil(aSO))
625 SALOMEDS::ChildIterator_var Itr = aStudy->NewChildIterator(aSO);
627 for(Itr->InitEx(true); Itr->More(); Itr->Next()) {
628 SALOMEDS::SObject_var aSObject = Itr->Value();
629 SALOMEDS::GenericAttribute_var anAttr;
630 if ( aSObject->FindAttribute(anAttr, "AttributeString")) {
631 aParameters = SALOMEDS::AttributeString::_narrow(anAttr)->Value();
632 SALOMEDS::ListOfListOfStrings_var aSections = aStudy->ParseVariables(aParameters);
634 cout<<"Entry : "<< aSObject->GetID()<<endl;
635 cout<<"aParameters : "<<aParameters<<endl;
637 TCollection_AsciiString anObjType;
638 CORBA::Object_var anObject = SMESH_Gen_i::SObjectToObject(aSObject);
639 SMESH::SMESH_Hypothesis_var aHyp = SMESH::SMESH_Hypothesis::_narrow(anObject);
640 if(!aHyp->_is_nil()) {
641 anObjType = TCollection_AsciiString(aHyp->GetName());
643 else if(SMESH::SMESH_Mesh_var aMesh = SMESH::SMESH_Mesh::_narrow(anObject)) {
644 anObjType = TCollection_AsciiString("Mesh");
647 cout<<"The object Type : "<<anObjType<<endl;
648 ObjectStates *aState = NULL;
649 if(anObjType == "LayerDistribution") {
650 aState = new LayerDistributionStates();
653 aState = new ObjectStates(anObjType);
655 for(int i = 0; i < aSections->length(); i++) {
657 SALOMEDS::ListOfStrings aListOfVars = aSections[i];
658 for(int j = 0;j<aListOfVars.length();j++) {
659 TCollection_AsciiString aVar(aListOfVars[j].in());
660 if(!aVar.IsEmpty() && aStudy->IsVariable(aVar.ToCString())) {
661 aVar.InsertBefore(1,"\"");
662 aVar.InsertAfter(aVar.Length(),"\"");
664 aVars.push_back(aVar);
666 cout<<"Variable: '"<<aVar<<"'"<<endl;
669 aState->AddState(aVars);
671 _objectMap.insert(pair<TCollection_AsciiString,ObjectStates*>(TCollection_AsciiString(aSObject->GetID()),aState));
676 //================================================================================
680 //================================================================================
681 void SMESH_NoteBook::AddCommand(const TCollection_AsciiString& theString)
684 cout<<theString<<endl;
685 Handle(_pyCommand) aCommand = new _pyCommand( theString, -1);
686 _commands.push_back(aCommand);
688 if ( aCommand->GetMethod() == "GetMeshEditor" ) { // MeshEditor creation
689 myMeshEditors.insert( make_pair( aCommand->GetResultValue(),
690 aCommand->GetObject() ) );
694 //================================================================================
698 //================================================================================
699 void SMESH_NoteBook::ProcessLayerDistribution()
701 // 1) Find all LayerDistribution states
702 vector<LayerDistributionStates*> aLDS;
703 TVariablesMap::const_iterator it = _objectMap.begin();
704 for(;it != _objectMap.end();it++) {
705 LayerDistributionStates* aLDStates = dynamic_cast<LayerDistributionStates*>(((*it).second));
706 if(aLDStates!=NULL) {
707 aLDS.push_back(aLDStates);
714 // 2) Initialize all type of 1D Distribution hypothesis
715 for(int i=0;i<_commands.size();i++){
716 for(int j =0;j < aLDS.size();j++){
717 TCollection_AsciiString aResultValue = _commands[i]->GetResultValue();
718 if(_commands[i]->GetMethod() == "CreateHypothesis" &&
719 aLDS[j]->HasDistribution(aResultValue)){
720 TCollection_AsciiString aType = _commands[i]->GetArg(1);
721 aType.RemoveAll('\'');
722 aLDS[j]->SetDistributionType(aResultValue,aType);
726 // 3) ... and replase variables ...
728 for(int i=0;i<_commands.size();i++){
729 for(int j =0;j < aLDS.size();j++){
730 TCollection_AsciiString anObject = _commands[i]->GetObject();
732 if(aLDS[j]->HasDistribution(anObject)) {
733 TCollection_AsciiString aType = aLDS[j]->GetDistributionType(anObject);
734 TCollection_AsciiString aMethod = _commands[i]->GetMethod();
735 if(aType == "LocalLength") {
736 if(aMethod == "SetLength") {
737 SetVariable(_commands[i], aLDS[j],0,1);
738 aLDS[j]->IncrementState();
740 else if(aMethod == "SetPrecision") {
741 SetVariable(_commands[i], aLDS[j],1,1);
742 aLDS[j]->IncrementState();
746 // Case for NumberOfSegments hypothesis
747 else if(aType == "NumberOfSegments"){
748 if(aMethod == "SetNumberOfSegments") {
749 SetVariable(_commands[i], aLDS[j],0,1);
750 if(aLDS[j]->GetCurrectState().size()==1)
751 aLDS[j]->IncrementState();
753 else if (aMethod == "SetScaleFactor") {
754 SetVariable(_commands[i], aLDS[j],1,1);
755 aLDS[j]->IncrementState();
759 else if( aType == "Deflection1D" ){
760 if(aMethod == "SetDeflection"){
761 SetVariable(_commands[i], aLDS[j],0,1);
762 aLDS[j]->IncrementState();
765 // Case for Arithmetic1D and StartEndLength hypothesis
766 else if(aType == "Arithmetic1D" || aType == "StartEndLength") {
767 if(aMethod == "SetLength") {
768 int anArgNb = (_commands[i]->GetArg(2) == "1") ? 0 : 1;
769 SetVariable(_commands[i], aLDS[j],anArgNb,1);
770 aLDS[j]->IncrementState();
777 //================================================================================
779 * \brief Return result script
781 //================================================================================
782 TCollection_AsciiString SMESH_NoteBook::GetResultScript() const
784 TCollection_AsciiString aResult;
785 for(int i=0;i<_commands.size();i++)
786 aResult+=_commands[i]->GetString()+"\n";
790 //================================================================================
792 * \brief Return value of the variable
794 //================================================================================
795 bool SMESH_NoteBook::GetReal(const TCollection_AsciiString& theVarName, double& theValue)
799 SMESH_Gen_i *aGen = SMESH_Gen_i::GetSMESHGen();
803 SALOMEDS::Study_ptr aStudy = aGen->GetCurrentStudy();
804 if(aStudy->_is_nil())
807 TCollection_AsciiString aVarName = theVarName;
808 aVarName.RemoveAll('\"');
810 if(aVarName.IsEmpty())
813 const char* aName = aVarName.ToCString();
814 if(aStudy->IsVariable(aName) && (aStudy->IsReal(aName) || aStudy->IsInteger(aName))) {
815 theValue = aStudy->GetReal(aVarName.ToCString());
824 * Set variable of the ObjectStates from position to the _pyCommand
825 * method as nbArg argument
827 void SetVariable(Handle(_pyCommand) theCommand, const ObjectStates* theStates, int position, int theArgNb)
829 if(theStates->GetCurrectState().size() > position)
830 if(!theStates->GetCurrectState().at(position).IsEmpty())
831 theCommand->SetArg(theArgNb,theStates->GetCurrectState().at(position));